From d7e6813af23f9308732f44bb16021fc718f01f8a Mon Sep 17 00:00:00 2001 From: Art Wild Date: Thu, 29 Nov 2018 12:20:29 -0500 Subject: [PATCH] make in datetime format: 'T' optional and case-insensitive & 'Z' also case-insensitive --- src/TOML.jl | 2 +- src/parser.jl | 8 ++++---- test/runtests.jl | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/TOML.jl b/src/TOML.jl index 78a9916..96c813c 100644 --- a/src/TOML.jl +++ b/src/TOML.jl @@ -1,7 +1,7 @@ module TOML import Dates - + include("parser.jl") include("print.jl") diff --git a/src/parser.jl b/src/parser.jl index e2d08c1..af8ca49 100644 --- a/src/parser.jl +++ b/src/parser.jl @@ -103,10 +103,10 @@ function peek(p::Parser) end "Returns `true` and consumes the next character if it matches `ch`, otherwise do nothing and return `false`" -function consume(p::Parser, ch::AbstractChar) +function consume(p::Parser, ch::AbstractChar...) eof(p) && return false c = peek(p) - if get(c) == ch + if get(c) in ch read(p) return true else @@ -425,7 +425,7 @@ function datetime(p::Parser, syear::String, st::Integer) month, valid = parsetwodigits(p, valid) valid = valid && consume(p, '-') day, valid = parsetwodigits(p, valid) - valid = valid && consume(p, 'T') + valid = valid && consume(p, 't', 'T', ' ') hour, valid = parsetwodigits(p, valid) valid = valid && consume(p, ':') minute, valid = parsetwodigits(p, valid) @@ -460,7 +460,7 @@ function datetime(p::Parser, syear::String, st::Integer) tzplus = true tzminus = false tzsign = true - if valid && !consume(p, 'Z') + if valid && !consume(p, 'Z', 'z') tzplus = consume(p, '+') if !tzplus tzminus = consume(p, '-') diff --git a/test/runtests.jl b/test/runtests.jl index f2aa295..627a16c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -358,6 +358,8 @@ trimmed in raw strings. @testset "Datetime" begin @testval("2016-09-09T09:09:09Z", Dates.DateTime(2016,9,9,9,9,9)) + @testval("2016-09-09 09:09:09Z", Dates.DateTime(2016,9,9,9,9,9)) + @testval("2016-09-09t09:09:09z", Dates.DateTime(2016,9,9,9,9,9)) @testval("2016-09-09T09:09:09.0Z", Dates.DateTime(2016,9,9,9,9,9)) @testval("2016-09-09T09:09:09.0+10:00", Dates.DateTime(2016,9,9,19,9,9)) @testval("2016-09-09T09:09:09.012-02:00", Dates.DateTime(2016,9,9,7,9,9,12)) @@ -367,6 +369,8 @@ trimmed in raw strings. @fail("foo = 2016-09-09T09:09:09+2:00", "malformed date literal") @fail("foo = 2016-09-09T09:09:09-2:00", "malformed date literal") @fail("foo = 2016-09-09T09:09:09Z-2:00", "expected a newline after a key") + @fail("foo = 2016-09-09s09:09:09Z", "malformed date literal") + @fail("foo = 2016-09-09 09:09:09x", "malformed date literal") end