Skip to content

Commit

Permalink
Improve print(::AnchoredInterval{P,ZonedDateTime})
Browse files Browse the repository at this point in the history
Fixes a corner case in print(::AnchoredInterval{P,ZonedDateTime}) in
which the time is omitted, in which case the time zone might be
mistaken for the time.

Closes #23
  • Loading branch information
spurll committed May 1, 2018
1 parent b882caa commit e8b2988
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/description.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function description(dt::AbstractDateTime, p::Period, suffix::String)
if p isa TimePeriod
return "$ds $(prefix(p))$suffix$ts"
else
return "$(prefix(p))$suffix $ds$(ts == "00:00:00" ? "" : " $ts")"
ts = (ts == "00:00:00" && !isa(dt, ZonedDateTime)) ? "" : " $ts"
return "$(prefix(p))$suffix $ds$ts"
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ using Intervals: canonicalize
@test sprint(show, interval) ==
"AnchoredInterval{-1 day, Date}(2016-08-11, Inclusivity(false, true))"

# Prevent confusion when dealing with time zones by ensuring that the full date and
# time are displayed
zdt = ceil(ZonedDateTime(dt, tz"America/Winnipeg"), Day)
interval = AnchoredInterval{Day(-1)}(zdt)
@test string(interval) == "(DE 2016-08-12 00:00:00-05:00]"
@test sprint(showcompact, interval) == string(interval)
@test sprint(show, interval) == string(
"AnchoredInterval{-1 day, TimeZones.ZonedDateTime}(2016-08-12T00:00:00-05:00, ",
"Inclusivity(false, true))"
)

interval = AnchoredInterval{Minute(-5)}(dt)
@test string(interval) == "(2016-08-11 5ME02:00]"
@test sprint(showcompact, interval) == string(interval)
Expand Down

0 comments on commit e8b2988

Please sign in to comment.