Skip to content

Commit 4d5604b

Browse files
committed
add json writer for Date and DateTime
1 parent 72e016e commit 4d5604b

File tree

4 files changed

+6
-0
lines changed

4 files changed

+6
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version = "0.11.0"
66
[deps]
77
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
88
Cobweb = "ec354790-cf28-43e8-bb59-b484409b7bad"
9+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
910
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
1011
EasyConfig = "acab07b0-f158-46d4-8913-50acef6d41fe"
1112
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
@@ -15,6 +16,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1516
Aqua = "0.8"
1617
Artifacts = "1.3"
1718
Cobweb = "0.6, 0.7"
19+
Dates = "1.11.0"
1820
Downloads = "1.6"
1921
EasyConfig = "0.1"
2022
JSON3 = "1.14"

src/PlotlyLight.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module PlotlyLight
33
using Artifacts: @artifact_str
44
using Downloads: download
55
using Random: randstring
6+
using Dates
67

78
using JSON3: JSON3
89
using EasyConfig: Config

src/json.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ json(io::IO, args...) = foreach(x -> json(io, x), args)
2222

2323
# Strings
2424
json(io::IO, x::Union{AbstractChar, AbstractString, Symbol}) = print(io, '"', x, '"')
25+
json(io::IO, x::DateTime) = json(io, Dates.format(x, "YYYY-mm-dd HH:MM:SS"))
26+
json(io::IO, x::Date) = json(io, Dates.format(x, "YYYY-mm-dd"))
2527

2628
# Numbers
2729
json(io::IO, x::Real) = isfinite(x) ? print(io, x) : print(io, "null")

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ html(x) = repr("text/html", x)
2525
@test json(NaN) == "null"
2626
@test json(Inf) == "null"
2727
@test json(-Inf) == "null"
28+
@test json(DateTime(2021,1,1)) == "\"2021-01-01 00:00:00\""
2829
end
2930

3031
#-----------------------------------------------------------------------------# Plot methods

0 commit comments

Comments
 (0)