From 31832316d3471dabad1f8cc780e51b479a1ab29e Mon Sep 17 00:00:00 2001 From: Joao Aparicio Date: Sun, 6 Apr 2025 16:56:33 -0500 Subject: [PATCH 1/4] Add test: JSON3 roundtrip --- Project.toml | 4 +++- test/runtests.jl | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 97b8bb1..622ec3a 100644 --- a/Project.toml +++ b/Project.toml @@ -16,6 +16,7 @@ UnixTimesMakieExt = ["Makie", "Observables"] UnixTimesTimeZonesExt = "TimeZones" [compat] +JSON3 = "1" Makie = "0.22" Observables = "0.5" TimeZones = "1" @@ -24,6 +25,7 @@ julia = "1.9" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" +JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" [targets] -test = ["Test", "TimeZones"] +test = ["Test", "TimeZones", "JSON3"] diff --git a/test/runtests.jl b/test/runtests.jl index ef499a8..81fac68 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,6 +2,7 @@ using UnixTimes using Dates using TimeZones using Test +import JSON3 @testset "UnixTime" begin @@ -102,4 +103,15 @@ end @test collect(t1:p:t2) isa Vector end +@testset "JSON3" begin + struct MyType + time::UnixTime + end + t = UnixTime("2025-01-01T00:00:00.000000000") + x = MyType(t) + s = JSON3.write(x) + out = JSON3.read(s, MyType) + @assert out.time == t +end + end From 2d5859f4a1c39cf211fbdeff3339be3401a946b9 Mon Sep 17 00:00:00 2001 From: Joao Aparicio Date: Sun, 6 Apr 2025 16:57:03 -0500 Subject: [PATCH 2/4] Add StructTypes extension --- Project.toml | 2 ++ ext/UnixTimesStructTypesExt.jl | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 ext/UnixTimesStructTypesExt.jl diff --git a/Project.toml b/Project.toml index 622ec3a..bb26dc4 100644 --- a/Project.toml +++ b/Project.toml @@ -10,9 +10,11 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" Observables = "510215fc-4207-5dde-b226-833fc4488ee2" TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" +StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4" [extensions] UnixTimesMakieExt = ["Makie", "Observables"] +UnixTimesStructTypesExt = "StructTypes" UnixTimesTimeZonesExt = "TimeZones" [compat] diff --git a/ext/UnixTimesStructTypesExt.jl b/ext/UnixTimesStructTypesExt.jl new file mode 100644 index 0000000..7321603 --- /dev/null +++ b/ext/UnixTimesStructTypesExt.jl @@ -0,0 +1,13 @@ +module UnixTimesStructTypesExt + +using Dates +using StructTypes +using UnixTimes + +StructTypes.StructType(::Type{UnixTime}) = StructTypes.CustomStruct() +StructTypes.lower(x::UnixTime) = Dates.value(x) +StructTypes.lowertype(::Type{UnixTime}) = Int64 +StructTypes.construct(::Type{UnixTime}, x::Int64) = + UnixTime(Dates.UTInstant(Dates.Nanosecond(x))) + +end From 7adf83ea40b0fa2272f2d268ae7c7131020088bb Mon Sep 17 00:00:00 2001 From: Joao Aparicio Date: Sun, 6 Apr 2025 17:16:57 -0500 Subject: [PATCH 3/4] Bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index bb26dc4..ea7d85e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "UnixTimes" uuid = "ab1a18e7-b408-4913-896c-624bb82ed7f4" authors = ["Christian Rorvik "] -version = "1.6.0" +version = "1.7.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" From 8fce6c7a09c5dc0c971a581c94411e6c5cf8742a Mon Sep 17 00:00:00 2001 From: Joao Aparicio Date: Sun, 27 Apr 2025 14:36:35 -0500 Subject: [PATCH 4/4] Remove JSON3 tests --- Project.toml | 4 +--- test/runtests.jl | 12 ------------ 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/Project.toml b/Project.toml index ea7d85e..8404fd5 100644 --- a/Project.toml +++ b/Project.toml @@ -18,7 +18,6 @@ UnixTimesStructTypesExt = "StructTypes" UnixTimesTimeZonesExt = "TimeZones" [compat] -JSON3 = "1" Makie = "0.22" Observables = "0.5" TimeZones = "1" @@ -27,7 +26,6 @@ julia = "1.9" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" -JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" [targets] -test = ["Test", "TimeZones", "JSON3"] +test = ["Test", "TimeZones"] diff --git a/test/runtests.jl b/test/runtests.jl index 81fac68..ef499a8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,6 @@ using UnixTimes using Dates using TimeZones using Test -import JSON3 @testset "UnixTime" begin @@ -103,15 +102,4 @@ end @test collect(t1:p:t2) isa Vector end -@testset "JSON3" begin - struct MyType - time::UnixTime - end - t = UnixTime("2025-01-01T00:00:00.000000000") - x = MyType(t) - s = JSON3.write(x) - out = JSON3.read(s, MyType) - @assert out.time == t -end - end