Skip to content

Commit

Permalink
Update version and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaras committed Mar 12, 2021
1 parent 04ed902 commit a6b9305
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
@@ -1,7 +1,7 @@
name = "UnixTimes"
uuid = "ab1a18e7-b408-4913-896c-624bb82ed7f4"
authors = ["Christian Rorvik <christian.rorvik@gmail.com>"]
version = "1.0.0"
version = "1.1.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
3 changes: 2 additions & 1 deletion src/UnixTimes.jl
Expand Up @@ -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}
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Expand Up @@ -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)
Expand Down

0 comments on commit a6b9305

Please sign in to comment.