Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Parse readable datetime format #13

Merged
merged 1 commit into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/TOML.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TOML

import Dates

include("parser.jl")
include("print.jl")

Expand Down
8 changes: 4 additions & 4 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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, '-')
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down