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

Add support for week-of-month. #1468

Merged
merged 4 commits into from
Mar 21, 2022
Merged

Conversation

mildgravitas
Copy link
Contributor

@mildgravitas mildgravitas commented Jan 4, 2022

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').

@mildgravitas mildgravitas marked this pull request as ready for review January 4, 2022 12:46
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;
Copy link
Member

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?

Copy link
Contributor Author

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...

Copy link
Contributor Author

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.

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • provider/testdata/data/testdata.postcard is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

gregtatum
gregtatum previously approved these changes Jan 14, 2022
Copy link
Member

@gregtatum gregtatum left a 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. 👍

components/datetime/src/skeleton/error.rs Show resolved Hide resolved
components/datetime/src/options/components.rs Outdated Show resolved Hide resolved
components/datetime/src/options/components.rs Outdated Show resolved Hide resolved
components/datetime/src/date.rs Outdated Show resolved Hide resolved
components/datetime/src/date.rs Show resolved Hide resolved
@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • components/datetime/src/date.rs is different
  • components/datetime/src/options/components.rs is different
  • components/datetime/src/pattern/runtime/plural.rs is different
  • components/datetime/src/skeleton/mod.rs is different
  • components/datetime/tests/fixtures/tests/components-partial-matches.json is now changed in the branch
  • provider/testdata/data/testdata.postcard is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

zbraniecki
zbraniecki previously approved these changes Feb 3, 2022
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@sffc
Copy link
Member

sffc commented Feb 17, 2022

@mildgravitas Can you update the postcard file again, and then merge? You should have merge access now.

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • components/datetime/src/fields/symbols.rs is different
  • components/datetime/src/format/datetime.rs is different
  • components/datetime/src/pattern/runtime/plural.rs is different
  • components/datetime/src/skeleton/mod.rs is different
  • provider/testdata/data/testdata.postcard is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • components/calendar/src/arithmetic.rs is different
  • components/datetime/src/date.rs is different
  • components/datetime/src/fields/symbols.rs is different
  • components/datetime/src/format/datetime.rs is different
  • components/datetime/src/skeleton/error.rs is different
  • components/datetime/src/skeleton/mod.rs is different
  • components/datetime/tests/fixtures/tests/components-exact-matches.json is different
  • components/datetime/tests/fixtures/tests/components-partial-matches.json is different
  • provider/testdata/data/testdata.postcard is no longer changed in the branch

View Diff Across 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').
@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • provider/testdata/data/testdata.postcard is now changed in the branch

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@mildgravitas
Copy link
Contributor Author

Rebased onto 0fd8cde. I had to update components-exact-matches.json too from #1366. PTAL.

@sffc
Copy link
Member

sffc commented Mar 19, 2022

@mildgravitas Since @gregtatum is on PTO, feel free to hit the merge button!

Copy link
Member

@gregtatum gregtatum left a 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!

@gregtatum gregtatum merged commit d3cbc28 into unicode-org:main Mar 21, 2022
@mildgravitas mildgravitas deleted the week_of_month branch March 23, 2022 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for week of month field "W" Implement year-week calculations for formatting
5 participants