Skip to content

Commit

Permalink
Add eps for ZonedDateTime (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Sep 3, 2018
1 parent 47a0c86 commit d3cf5b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/accessors.jl
@@ -1,3 +1,4 @@
import Base: eps
import Compat.Dates: Hour, Minute, Second, Millisecond,
days, hour, minute, second, millisecond

Expand Down Expand Up @@ -33,3 +34,5 @@ for period in (:Hour, :Minute, :Second, :Millisecond)
$period(zdt::ZonedDateTime) = $period($accessor(zdt))
end
end

eps(::ZonedDateTime) = Millisecond(1)
3 changes: 2 additions & 1 deletion src/discovery.jl
Expand Up @@ -212,7 +212,8 @@ show_next_transition

function show_next_transition(io::IO, zdt::ZonedDateTime)
instant = next_transition_instant(zdt)
from, to = instant - Millisecond(1), instant + Millisecond(0)
epsilon = eps(instant)
from, to = instant - epsilon, instant + zero(epsilon)
direction = value(to.zone.offset - from.zone.offset) < 0 ? "Backward" : "Forward"

function zdt_format(zdt)
Expand Down
4 changes: 3 additions & 1 deletion test/accessors.jl
@@ -1,5 +1,5 @@
import Compat.Dates
import Compat.Dates: Second
import Compat.Dates: Second, Millisecond

warsaw = resolve("Europe/Warsaw", tzdata["europe"]...)
fixed = FixedTimeZone("Fixed", -7200, 3600)
Expand All @@ -15,6 +15,8 @@ zdt = ZonedDateTime(DateTime(2014,6,12,23,59,58,57), fixed)
@test TimeZones.second(zdt) == 58
@test TimeZones.millisecond(zdt) == 57

@test eps(zdt) == Millisecond(1)

# Make sure that Dates accessors work with ZonedDateTime.
@test Dates.year(zdt) == 2014
@test Dates.month(zdt) == 6
Expand Down

0 comments on commit d3cf5b4

Please sign in to comment.