-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add start_day
parameter to Time#at_beginning_of_week
#13446
Add start_day
parameter to Time#at_beginning_of_week
#13446
Conversation
Due to https://crystal-lang.org/reference/1.8/syntax_and_semantics/autocasting.html#symbol-autocasting, I'd probably be in favor of dropping support for |
That's awesome! Thanks for pointing that out. I'll put a commit together now EDIT: Removed the overload here |
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
Thanks for your contribution, @DanielGilchrist. 🙇 Now we already have PR and that's great. I'd still ask you to open an issue to propose this change (you can basically take the PR description for that), so we can discuss the feature there. |
Thank you for your response and apologies for not reading the contribution guide thoroughly enough 😅 I'll make sure to give it a good read for future contributions I'll put this PR into draft mode and make an issue now :) Thanks! |
#13446 has had a couple of upvotes (including from two Core Team members), so I think we're good to move on. Sorry for the inconvenience and thanks for following along🙇 Simplifying the documentation as suggested in #13446 (comment) would be good. Then this should be ready to roll. |
spec/std/time/time_spec.cr
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no specs to show that the hour/minute/second components become 0 after a call to #at_beginning_of_week
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for calling this out I have addressed this here: a4b6914
(#13446)
Let me know if you had any more cases in mind :~)
…d show en example without an argument Co-Authored-By: Sijawusz Pur Rahnama <[email protected]>
…#at_beginning_of_week`
No worries and thank you for your time!
I've addressed the remaining comments and relevant specs are passing locally let me know if there are any other changes required before merge :~) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a small proposal to improve reproduceability of the example by using a fixed timestamp instead of Time.local
.
Co-authored-by: Johannes Müller <[email protected]>
start_day
argument for Time#at_beginning_of_week
start_day
parameter to Time#at_beginning_of_week
Closes #13447
Currently when using
Time#at_beginning_of_week
it assumes the start of the week to be Monday. This works great for many use cases but sometimes we may want to assume the beginning of the week as another day (e.g. Sunday is also commonly considered to be "the beginning of the week")I've opted to allow this in 2 forms: With aTime::DayOfWeek
which is type safe and for convenience, aString
orSymbol
that raises anArgumentError
if an invalid value is passedEDIT: @Blacksmoke16 pointed out here that we can leverage Symbol autocasting for enum members and avoid the overload altogether
This kind of functionality is provided by Rails which is where I got the inspiration from https://api.rubyonrails.org/classes/DateAndTime/Calculations.html#method-i-beginning_of_week
If we decide this is worth having in the standard library I'd also be more than happy to implement it for
Time#at_end_of_week
in this PR or a separate one as well :)Docs
Current
After this PR
Thanks!