Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dates round/floor/ceil arguments switched #47786

Open
jariji opened this issue Dec 2, 2022 · 7 comments · May be fixed by #47843
Open

Dates round/floor/ceil arguments switched #47786

jariji opened this issue Dec 2, 2022 · 7 comments · May be fixed by #47843
Labels
domain:dates Dates, times, and the Dates stdlib module good first issue Indicates a good issue for first-time contributors to Julia status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@jariji
Copy link
Contributor

jariji commented Dec 2, 2022

round(T, x) is the normal API, but in Dates.jl the arguments are reversed.

julia> ceil(today(), Week)
2022-12-05

julia> ceil(Week, today())
ERROR: MethodError: no method matching ceil(::Type{Week}, ::Date)
@brenhinkeller brenhinkeller added the domain:dates Dates, times, and the Dates stdlib module label Dec 3, 2022
@LilithHafner LilithHafner added the status:help wanted Indicates that a maintainer wants help on an issue or pull request label Dec 3, 2022
@LilithHafner
Copy link
Member

Thanks. We can't remove ceil(today(), Week) till 2.0, but we should add the normal order.

@oscardssmith
Copy link
Member

we can deprecate the wrong order, and IMO should do so.

@StefanKarpinski
Copy link
Sponsor Member

(Note that deprecations are silent by default, so this is not breaking.)

@oscardssmith oscardssmith added the good first issue Indicates a good issue for first-time contributors to Julia label Dec 5, 2022
@x0samnan
Copy link

x0samnan commented Dec 8, 2022

Hello, I am new to Open-Source. I have tried Julia and want to get involved in the community. Since, this is a good first issue, can I work on it?

Edit: Please, refer to #47843. I have created a Pull request.

@ndinsmore
Copy link
Contributor

ndinsmore commented Dec 9, 2022

@oscardssmith & @LilithHafner There is one round method that it looks like you create an ambiguity that you can't fix without breaking:

function Base.round(precision::ConvertiblePeriod, x::ConvertiblePeriod, r::RoundingMode{:NearestTiesUp})
    f, c = floorceil(precision, x)
    _x, _f, _c = promote(x, f, c)
    return (_x - _f) < (_c - _x) ? f : c
end
Base.round(x::ConvertiblePeriod, precision::ConvertiblePeriod, r::RoundingMode{:NearestTiesUp}) = Base.round(precision, x, r) #@deprecate

Please note that this is from my own PR that I was working on before I saw #47843 the bottom line is what typically would be @deprecate but it appears that you can't do that on an overload of 'Base.round'.

I have a PR ready that covers everything and the tests.

Additional definitions of rounding that cause issues

# Base.round(x::TimeTypeOrPeriod, p::Period, r::RoundingMode{:Down}) = Base.round(p,x,r) #@deprecate
Base.round(p::Period, x::TimeTypeOrPeriod, r::RoundingMode{:Down}) = Base.floor(p, x)
# Base.round(x::TimeTypeOrPeriod, p::Period, r::RoundingMode{:Up}) = Base.round(p,x,r) #@deprecate
Base.round(p::Period, x::TimeTypeOrPeriod, r::RoundingMode{:Up}) = Base.ceil(p, x)

# Base.round(::TimeTypeOrPeriod, p::Period, ::RoundingMode) = throw(DomainError(p)) #@deprecate
Base.round(p::Period, ::TimeTypeOrPeriod, ::RoundingMode) = throw(DomainError(p))

# Base.round(x::TimeTypeOrPeriod, p::Period) = Base.round(p, x, RoundNearestTiesUp) #@deprecate
Base.round(p::Period, x::TimeTypeOrPeriod) = Base.round(p, x, RoundNearestTiesUp)

@sostock
Copy link
Contributor

sostock commented Aug 17, 2023

Previous discussion: #18574, #34782.

@jariji
Copy link
Contributor Author

jariji commented Aug 17, 2023

#18574 (comment) says

For this reason, when we're looking at trunc(dt::TimeType, ::Type{Period}), the type in question is really more analogous to digits in trunc([T,] x, [digits, [base]]) rather than T.

The positional digits argument is no longer the API of trunc:

  trunc([T,] x)
  trunc(x; digits::Integer= [, base = 10])
  trunc(x; sigdigits::Integer= [, base = 10])

so this justification by analogy doesn't apply anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:dates Dates, times, and the Dates stdlib module good first issue Indicates a good issue for first-time contributors to Julia status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants