Skip to content

Commit e8b2988

Browse files
committed
Improve print(::AnchoredInterval{P,ZonedDateTime})
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
1 parent b882caa commit e8b2988

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/description.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ function description(dt::AbstractDateTime, p::Period, suffix::String)
3939
if p isa TimePeriod
4040
return "$ds $(prefix(p))$suffix$ts"
4141
else
42-
return "$(prefix(p))$suffix $ds$(ts == "00:00:00" ? "" : " $ts")"
42+
ts = (ts == "00:00:00" && !isa(dt, ZonedDateTime)) ? "" : " $ts"
43+
return "$(prefix(p))$suffix $ds$ts"
4344
end
4445
end
4546

test/anchoredinterval.jl

+11
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ using Intervals: canonicalize
226226
@test sprint(show, interval) ==
227227
"AnchoredInterval{-1 day, Date}(2016-08-11, Inclusivity(false, true))"
228228

229+
# Prevent confusion when dealing with time zones by ensuring that the full date and
230+
# time are displayed
231+
zdt = ceil(ZonedDateTime(dt, tz"America/Winnipeg"), Day)
232+
interval = AnchoredInterval{Day(-1)}(zdt)
233+
@test string(interval) == "(DE 2016-08-12 00:00:00-05:00]"
234+
@test sprint(showcompact, interval) == string(interval)
235+
@test sprint(show, interval) == string(
236+
"AnchoredInterval{-1 day, TimeZones.ZonedDateTime}(2016-08-12T00:00:00-05:00, ",
237+
"Inclusivity(false, true))"
238+
)
239+
229240
interval = AnchoredInterval{Minute(-5)}(dt)
230241
@test string(interval) == "(2016-08-11 5ME02:00]"
231242
@test sprint(showcompact, interval) == string(interval)

0 commit comments

Comments
 (0)