-
Notifications
You must be signed in to change notification settings - Fork 174
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 support for week-of-month. #1468
Conversation
components/datetime/src/date.rs
Outdated
first_weekday: IsoWeekday, | ||
) -> Result<WeekOfMonth, DateTimeError> { | ||
// This value isn't used by week_of() given that we use a calendar with min_week_days = 1. | ||
const UNUSED_DAYS_IN_MONTH: u16 = 60; |
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.
Thought
This seems a little bit strange to me. But I'm not familiar enough with this code to know what alternatives would be.
As someone who is not familiar with the week_of
code, I'm not sure why the min_week_days = 1
is relevant, or why this value is 60.
Question
Is the 60 an arbitrary value, since this is "unused," or does this value have to be 60?
Question
I wonder if we can't do something a bit cleaner using Option
.
Could week_of::week_of
potentially take an Option
?
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.
My bad, I was leaking arithmetic.rs's implementation details there. I've added a simple_week_of() method to arithmetic.rs that encapsulates those details instead. If that's still non-ideal I can add an implementation for t simple_week_of() rather than call into the more complete week_of(); I'd rather avoid having Options complicate the week_of signature...
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.
With min_week_days
= 1 week_of()
boils down to ceil((day - 1 + (first_day_of_month - first_weekday)) / 7). num_days_in_previous_unit
& num_days_in_unit
only come into play for min_week_days
> 1 in which case a day in the current month/year can get counted as part of the previous or next month/year.
f0fac1d
to
9a10562
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
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, looks good to me. 👍
9a10562
to
aa23afd
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
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.
lgtm!
@mildgravitas Can you update the postcard file again, and then merge? You should have merge access now. |
aa23afd
to
5d798fc
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
5d798fc
to
586bc5b
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
Contrary to UTS 35 this always uses min_days = 1 as there's no month of week-of-month field so there would be inconsistencies otherwise (e.g. in the ISO calendar 2021-01-01 is the last week of December but 'MMMMW' would have it formatted as 'week 5 of January').
586bc5b
to
a7eb37a
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
@mildgravitas Since @gregtatum is on PTO, feel free to hit the merge button! |
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 the rebase!
Fixes #502
Fixes #488
Contrary to UTS 35 this always uses min_days = 1 as there's no month of
week-of-month field so there would be inconsistencies otherwise (e.g. in
the ISO calendar 2021-01-01 is the last week of December but 'MMMMW' would
have it formatted as 'week 5 of January').