diff --git a/docs/src/dates.md b/docs/src/dates.md index 9fa0238a..521dc9e0 100644 --- a/docs/src/dates.md +++ b/docs/src/dates.md @@ -12,7 +12,7 @@ end The `Dates.FixedPeriod` union type includes all `Dates.Period`s that represent a fixed period of time, i.e., `Dates.Week`, `Dates.Day`, `Dates.Hour`, `Dates.Minute`, `Dates.Second`, `Dates.Millisecond`, `Dates.Microsecond`, and `Dates.Nanosecond`. These types can be converted to `Quantity`s or used in place of them. !!! note - `Dates.Year` does not represent a fixed period and cannot be converted to a `Quantity`. While Unitful's `yr` unit is exactly equal to 365.2425 days, a `Dates.Year` may contain 365 or 366 days (see [`Dates.isleapyear`](@ref)). + `Dates.Year` does not represent a fixed period and cannot be converted to a `Quantity`. While Unitful's `yr` unit is exactly equal to 365.2425 days, a `Dates.Year` may contain 365 or 366 days (see [`Dates.days(::Year)`](@ref) and [`Dates.isleapyear`](@ref)). Each `FixedPeriod` is considered equivalent to a `Quantity`. For example, `Dates.Millisecond(5)` corresponds to the quantity `Int64(5)*u"ms"`. A `FixedPeriod` can be converted to the equivalent `Quantity` with a constructor: diff --git a/test/dates.jl b/test/dates.jl index 661743e1..75a65836 100644 --- a/test/dates.jl +++ b/test/dates.jl @@ -206,6 +206,7 @@ @test u"μs"(CompoundPeriod(Day(365),Hour(5),Minute(49),Second(12))) === Rational{Int64}(31_556_952_000_000,1)u"μs" @test uconvert(u"ns", CompoundPeriod(Day(365),Hour(5),Minute(49),Second(12))) === Int64(31_556_952_000_000_000)u"ns" @test u"ns"(CompoundPeriod(Day(365),Hour(5),Minute(49),Second(12))) === Int64(31_556_952_000_000_000)u"ns" + @test uconvert(u"ms", 1u"yr") == (Dates.toms(Year(1)))u"ms" # Compare to Dates stdlib value of a year @test uconvert(u"ps", CompoundPeriod(Week(1),Hour(-1))) === Int64(601_200_000_000_000_000)u"ps" @test u"ps"(CompoundPeriod(Week(1),Hour(-1))) === Int64(601_200_000_000_000_000)u"ps" @test_throws DimensionError uconvert(u"m", CompoundPeriod(Day(365),Hour(5),Minute(49),Second(12)))