Skip to content

Commit

Permalink
Fix documentation; remove TimeZone calls in tests
Browse files Browse the repository at this point in the history
Minor tweaks to documentation as requested in PR comments.
Replaced calls to `TimeZone` with calls to `resolve` in test cases.
  • Loading branch information
spurll committed Jul 12, 2016
1 parent 96fa4a2 commit 6f7113a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions docs/rounding.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Rounding operations (`floor`, `ceil`, and `round`) on `ZonedDateTime`s are perfo
and should generally behave as expected. When `VariableTimeZone` transitions are involved,
however, unexpected behaviour may be encountered.

Instead of performing rounding operations on the `ZonedDateTime`'s internal UTC `DateTime`,
which would be computationally less expensive, rounding is done in the local time zone.
This ensures that rounding behaves as expected and is maximally meaningful.
Instead of performing rounding operations on a UTC representation of the `ZonedDateTime`,
which would in some cases be computationally less expensive, rounding is done in the local
time zone. This ensures that rounding behaves as expected and is maximally meaningful.

If rounding were done in UTC, consider how rounding to the nearest day would be resolved for
non-UTC time zones: the result would be 00:00 UTC, which wouldn't be midnight local time.
Expand All @@ -22,7 +22,7 @@ When the target resolution is a `TimePeriod` the likelihood of encountering an a
non-existent time (due to daylight saving time transitions) is increased. To resolve this
issue, rounding a `ZonedDateTime` with a `VariableTimeZone` to a `TimePeriod` uses the
`DateTime` value in the appropriate `FixedTimeZone`, then reconverts it to a `ZonedDateTime`
in the appropriate `VariableTimeZone` afterward.
in the appropriate `VariableTimeZone` afterward. (See [Examples](#examples) below.)

### Rounding to a DatePeriod

Expand Down
13 changes: 8 additions & 5 deletions src/timezones/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ end

"""
floor(zdt::ZonedDateTime, p::Period) -> ZonedDateTime
floor(zdt::ZonedDateTime, p::Type{Period}) -> ZonedDateTime
Returns the nearest `ZonedDateTime` less than or equal to `zdt` at resolution `p`. The
result will be in the same time zone as `zdt`.
Expand All @@ -44,10 +45,11 @@ julia> floor(zdt, Dates.Hour)
2016-03-13T01:00:00-06:00
```
"""
Base.floor(::TimeZones.ZonedDateTime, ::Dates.Period)
Base.floor(::TimeZones.ZonedDateTime, ::Union{Dates.Period, Type{Dates.Period}})

"""
ceil(zdt::ZonedDateTime, p::Period) -> ZonedDateTime
ceil(zdt::ZonedDateTime, p::Type{Period}) -> ZonedDateTime
Returns the nearest `ZonedDateTime` greater than or equal to `zdt` at resolution `p`.
The result will be in the same time zone as `zdt`.
Expand All @@ -69,14 +71,15 @@ julia> zdt = ZonedDateTime(2016, 3, 13, 1, 45, TimeZone("America/Winnipeg"))
julia> ceil(zdt, Dates.Day)
2016-03-14T00:00:00-05:00
julia> ceilj(zdt, Dates.Hour)
julia> ceil(zdt, Dates.Hour)
2016-03-13T03:00:00-05:00
```
"""
Base.ceil(::TimeZones.ZonedDateTime, ::Dates.Period) # Defined in base/dates/rounding.jl
Base.ceil(::TimeZones.ZonedDateTime, ::Union{Dates.Period, Type{Dates.Period}})

"""
round(zdt::ZonedDateTime, p::Period, [r::RoundingMode]) -> ZonedDateTime
round(zdt::ZonedDateTime, p::Type{Period}, [r::RoundingMode]) -> ZonedDateTime
Returns the `ZonedDateTime` nearest to `zdt` at resolution `p`. The result will be in the
same time zone as `zdt`. By default (`RoundNearestTiesUp`), ties (e.g., rounding 9:30 to the
Expand Down Expand Up @@ -142,5 +145,5 @@ julia> round(zdt, Dates.Hour)
julia> round(zdt, Dates.Day)
ERROR: Local DateTime 1996-10-26T00:00:00 is ambiguious
```
"""
Base.round(::TimeZones.ZonedDateTime, ::Dates.Period) # Defined in base/dates/rounding.jl
""" # Defined in base/dates/rounding.jl
Base.round(::TimeZones.ZonedDateTime, ::Union{Dates.Period, Type{Dates.Period}})
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const TZFILE_DIR = joinpath(PKG_DIR, "test", "tzfile")
# Note: resolving only the time zones we want is much faster than running compile which
# recompiles all the time zones.
tzdata = Dict{AbstractString,Tuple{ZoneDict,RuleDict}}()
for name in ("australasia", "europe", "northamerica")
for name in ("asia", "australasia", "europe", "northamerica")
tzdata[name] = tzparse(joinpath(TZDATA_DIR, name))
end

Expand Down
8 changes: 4 additions & 4 deletions test/timezones/rounding.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
utc = FixedTimeZone("UTC")
fixed = FixedTimeZone("UTC-06:00")
winnipeg = TimeZone("America/Winnipeg") # UTC-6:00 (UTC-5:00 during DST)
st_johns = TimeZone("America/St_Johns") # UTC-3:30 (UTC-2:30 during DST)
eucla = TimeZone("Australia/Eucla") # UTC+8:45
colombo = TimeZone("Asia/Colombo") # See note below
winnipeg = resolve("America/Winnipeg", tzdata["northamerica"]...) # UTC-6:00 (or UTC-5:00)
st_johns = resolve("America/St_Johns", tzdata["northamerica"]...) # UTC-3:30 (or UTC-2:30)
eucla = resolve("Australia/Eucla", tzdata["australasia"]...) # UTC+8:45
colombo = resolve("Asia/Colombo", tzdata["asia"]...) # See note below

# On 1996-05-25 at 00:00, the Asia/Colombo time zone in Sri Lanka moved from Indian Standard
# Time (UTC+5:30) to Lanka Time (UTC+6:30). On 1996-10-26 at 00:30, Lanka Time was revised
Expand Down

0 comments on commit 6f7113a

Please sign in to comment.