I just noticed that the floor / ceil methods for Number and Period have the positional arguments inverted.
floor(Int, 3.5)
using Dates
floor(DateTime("2000-01-31"), Month)
From Slack, Dates should be consistent with Base.
Related: #18574
Out of curiosity, what has changed that the arguments against this proposal from #18574 are no longer valid?
I think just people keep getting confused by the order... Would it be too bad to have both methods?
ceil(dt::TimeType, p::Period) -> TimeType
ceil(p::Period, dt::TimeType) -> TimeType
ceil(x::Period, precision::T) where T <: Union{TimePeriod, Week, Day} -> T
ceil(precision::T, x::Period) where T <: Union{TimePeriod, Week, Day} -> T
As I already posted in https://github.com/JuliaLang/julia/pull/34810#issuecomment-593851089 I'm thinking that the original considerations in https://github.com/JuliaLang/julia/issues/18574 were right and the current behaviour is not inconsistent but missing functionality. It can be seen easily if we add a function which can round to a period while converting the time type:
round(Date, now(), Month, RoundUp) == Date(2020, 4) #at least for the month of the post 馃槃
Tl;Dr: rather add those missing functions and make only the 2nd argument a required one
I'd like to work on this, if I understand this correctly, we'd like the following to pass as tests in the end?
now_ = now()
for p in (Year, Month, Day)
for r in (RoundUp, RoundDown)
@test round(Date, now_, p, r) == round(Date(now_), p, r)
end
@test floor(Date, now_, p) == round(Date, now_, p, RoundDown)
@test ceil(Date, now_, p) == round(Date, now_, p, RoundUp)
end
Most helpful comment
I'd like to work on this, if I understand this correctly, we'd like the following to pass as tests in the end?