diff --git a/base/dates/rounding.jl b/base/dates/rounding.jl index 6a5ce62ca3d53..1ffbe586b7a38 100644 --- a/base/dates/rounding.jl +++ b/base/dates/rounding.jl @@ -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`. @@ -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`. diff --git a/doc/manual/dates.rst b/doc/manual/dates.rst index 253371b4d95a8..08b5ba148b228 100644 --- a/doc/manual/dates.rst +++ b/doc/manual/dates.rst @@ -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 `_ for additional information on methods exported from the :mod:`Dates` module. diff --git a/doc/stdlib/dates.rst b/doc/stdlib/dates.rst index cd0698b66b917..1cc554b42b613 100644 --- a/doc/stdlib/dates.rst +++ b/doc/stdlib/dates.rst @@ -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: @@ -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 @@ -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 diff --git a/doc/stdlib/strings.rst b/doc/stdlib/strings.rst index b92a95c3d3040..e5bb975d8745a 100644 --- a/doc/stdlib/strings.rst +++ b/doc/stdlib/strings.rst @@ -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. + diff --git a/test/dates/rounding.jl b/test/dates/rounding.jl index 8a1e208457c50..4cf852deb314d 100644 --- a/test/dates/rounding.jl +++ b/test/dates/rounding.jl @@ -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