From a6b9305e6dda628a191b193c96f26a89c186f904 Mon Sep 17 00:00:00 2001 From: Dan Taras Date: Fri, 12 Mar 2021 10:16:34 +0000 Subject: [PATCH] Update version and add unit test --- Project.toml | 2 +- src/UnixTimes.jl | 3 ++- test/runtests.jl | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 70ba007..b7944d5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "UnixTimes" uuid = "ab1a18e7-b408-4913-896c-624bb82ed7f4" authors = ["Christian Rorvik "] -version = "1.0.0" +version = "1.1.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/UnixTimes.jl b/src/UnixTimes.jl index ee47566..59dce20 100644 --- a/src/UnixTimes.jl +++ b/src/UnixTimes.jl @@ -7,7 +7,6 @@ export UnixTime export unix_now export UNIX_EPOCH -const UNIX_EPOCH = UnixTime(Dates.UTInstant(Nanosecond(0))) struct UnixTime <: Dates.AbstractDateTime instant::Dates.UTInstant{Nanosecond} @@ -26,6 +25,8 @@ function UnixTime( convert(UnixTime, DateTime(y, m, d, h, mi, s, ms)) + Nanosecond(us * 1000 + ns) end +const UNIX_EPOCH = UnixTime(Dates.UTInstant(Nanosecond(0))) + Dates.days(x::UnixTime) = Dates.days(convert(DateTime, x)) Dates.hour(x::UnixTime) = mod(fld(Dates.value(x), 3600_000_000_000), 24) Dates.minute(x::UnixTime) = mod(fld(Dates.value(x), 60_000_000_000), 60) diff --git a/test/runtests.jl b/test/runtests.jl index d4a147f..e464b55 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,6 +82,7 @@ end @test UnixTime(DateTime(2020, 1, 2, 3)) == UnixTime(2020, 1, 2, 3) @test DateTime(UnixTime(2020, 1, 2, 3)) == DateTime(2020, 1, 2, 3) @test Date(UnixTime(2020, 1, 2, 3)) == Date(2020, 1, 2) + @test Time(UnixTime(2020, 1, 2, 3, 4, 5, 6, 7, 8)) == Time(3, 4, 5, 6, 7, 8) @test UnixTime(Date(2020, 1, 2)) == UnixTime(2020, 1, 2) @test convert(UnixTime, DateTime(2020, 1, 2, 3)) == UnixTime(2020, 1, 2, 3) @test convert(DateTime, UnixTime(2020, 1, 2, 3)) == DateTime(2020, 1, 2, 3)