Skip to content

Commit

Permalink
Bugfix for date rounding test in 32-bit. Doc clarifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
spurll committed Jun 21, 2016
1 parent 33a4a49 commit 078f029
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions base/dates/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const DATETIMEEPOCH = value(DateTime(0))
const WEEKEPOCH = value(Date(0, 1, 3))

"""
epochdays2date(days) -> DateTime
epochdays2date(days) -> Date
Takes the number of days since the rounding epoch (`0000-01-01T00:00:00`) and returns the
corresponding `Date`.
Expand All @@ -22,7 +22,7 @@ returns the corresponding `DateTime`.
epochms2datetime(i) = DateTime(UTM(DATETIMEEPOCH + Int64(i)))

"""
date2epochdays(dt::DateTime) -> Int64
date2epochdays(dt::Date) -> Int64
Takes the given `Date` and returns the number of days since the rounding epoch
(`0000-01-01T00:00:00`) as an `Int64`.
Expand Down
12 changes: 6 additions & 6 deletions doc/manual/dates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,12 @@ Why round to the first day in July, even though it is month 7 (an odd number)? T
that months are 1-indexed (the first month is assigned 1), unlike hours, minutes, seconds,
and milliseconds (the first of which are assigned 0).

This means that rounding seconds, minutes, hours, or years (because the ISO 8601
specification includes a year zero) to an even multiple will result in that field having
an even value, while rounding to an even multiple of months will result in that field
having an odd value. Because both months and years may contain an irregular number of
days, whether rounding to an even number of days will result in an even value in the days
field is uncertain.
This means that rounding a :class:`DateTime` to an even multiple of seconds, minutes,
hours, or years (because the ISO 8601 specification includes a year zero) will result in
a :class:`DateTime` with an even value in that field, while rounding a :class:`DateTime`
to an even multiple of months will result in the months field having an odd value. Because
both months and years may contain an irregular number of days, whether rounding to an even
number of days will result in an even value in the days field is uncertain.


See the `API reference <http://docs.julialang.org/en/latest/stdlib/dates/>`_ for additional information on methods exported from the :mod:`Dates` module.
6 changes: 3 additions & 3 deletions doc/stdlib/dates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ or 15 minutes) with ``floor``, ``ceil``, or ``round``.
julia> round(DateTime(2016, 8, 6, 12, 0, 0), Dates.Day)
2016-08-07T00:00:00

Valid RoundingModes for ``round(::TimeType, ::Period, ::RoundingMode)`` are ``RoundNearestTiesUp`` (default), ``RoundDown`` (``floor``\ ), and ``RoundUp`` (``ceil``\ ).
Valid rounding modes for ``round(::TimeType, ::Period, ::RoundingMode)`` are ``RoundNearestTiesUp`` (default), ``RoundDown`` (``floor``\ ), and ``RoundUp`` (``ceil``\ ).

The following functions are not exported:

Expand All @@ -648,7 +648,7 @@ The following functions are not exported:
Simultaneously return the ``floor`` and ``ceil`` of a ``Date`` or ``DateTime`` at resolution ``p``\ . More efficient than calling both ``floor`` and ``ceil`` individually.

.. function:: epochdays2date(days) -> DateTime
.. function:: epochdays2date(days) -> Date

.. Docstring generated from Julia source
Expand All @@ -660,7 +660,7 @@ The following functions are not exported:
Takes the number of milliseconds since the rounding epoch (``0000-01-01T00:00:00``\ ) and returns the corresponding ``DateTime``\ .

.. function:: date2epochdays(dt::DateTime) -> Int64
.. function:: date2epochdays(dt::Date) -> Int64

.. Docstring generated from Julia source
Expand Down
1 change: 1 addition & 0 deletions doc/stdlib/strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,4 @@
.. Docstring generated from Julia source
Create a string from the address of a NUL-terminated UTF-32 string. A copy is made; the pointer can be safely freed. If ``length`` is specified, the string does not have to be NUL-terminated.

4 changes: 2 additions & 2 deletions test/dates/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
@test Dates.epochms2datetime(-86400000) == Dates.DateTime(-1, 12, 31)
@test Dates.epochms2datetime(0) == Dates.DateTime(0, 1, 1)
@test Dates.epochms2datetime(86400000) == Dates.DateTime(0, 1, 2)
@test Dates.epochms2datetime(736329 * 86400000) == Dates.DateTime(2016, 1, 1)
@test Dates.epochms2datetime(Int64(736329) * 86400000) == Dates.DateTime(2016, 1, 1)
@test Dates.date2epochdays(Dates.Date(-1, 12, 31)) == -1
@test Dates.date2epochdays(Dates.Date(0, 1, 1)) == 0
@test Dates.date2epochdays(Dates.Date(2016, 1, 1)) == 736329
@test Dates.datetime2epochms(Dates.DateTime(-1, 12, 31)) == -86400000
@test Dates.datetime2epochms(Dates.DateTime(0, 1, 1)) == 0
@test Dates.datetime2epochms(Dates.DateTime(2016, 1, 1)) == 736329 * 86400000
@test Dates.datetime2epochms(Dates.DateTime(2016, 1, 1)) == Int64(736329) * 86400000

# Basic rounding tests
dt = Dates.Date(2016, 2, 28) # Sunday
Expand Down

0 comments on commit 078f029

Please sign in to comment.