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

Implement localized week information #1454

Merged
merged 29 commits into from
Oct 12, 2023

Conversation

diesieben07
Copy link
Collaborator

@diesieben07 diesieben07 commented Jun 22, 2023

Use Intl.Locale#getWeekInfo to provide locale-dependent week information, such as the start of the week.

Fixes #1447

Current status:

  • Info.features reports on whether localized week info is available in the current environment
  • Info.getStartOfWeek: returns 1 (Monday) through 7 (Sunday) for first day of the week according to locale
  • Info.getMinimumDaysInFirstWeek for getting minimum days in the first week of the year
  • Info.getWeekendWeekdays for getting weekend days
  • DateTime#isWeekend: returns whether the current date is on the weekend according to the locale
  • DateTime#localWeekday: returns 1-7 for first to last day according to locale
  • DateTime#localWeekNumber and DateTime#localWeekYear; same as weekNumber and weekYear, but respecting the locale. I need to understand the math here before I can implement it.
  • DateTime#hasSame, DateTime#startOf, DateTime#endOf and Interval#count accept a new option useLocaleWeeks, when enabled the week unit will act according to the locale week information
  • Tests
  • (Potentially) Caching for the localized week data (weekNumber, weekYear)
  • Investigate how to let the user override the defaults. There are BCP tags to set the start of the week, but browsers seem to ignore them, so we probably need to provide our own configuration option, similar to numberingSystem.
  • Accept locale-based week units in DateTime.fromObject and DateTime#set
  • Add DateTime#weeksInLocalWeekYear, analogous to weeksInWeekYear
  • Investigate supporting formatting tokens for localWeekNumber and localWeekYear.
  • Documentation

src/datetime.js Outdated Show resolved Hide resolved
@icambron
Copy link
Member

Looks really good. Left one comment

@diesieben07 diesieben07 marked this pull request as ready for review September 17, 2023 18:28
@diesieben07
Copy link
Collaborator Author

After a lot of work, this is now ready for review. All features I wanted to add have been implemented, including tests.

@icambron
Copy link
Member

This is great. Merging as-is.

@icambron icambron merged commit 1b8679e into moment:master Oct 12, 2023
2 checks passed
@carvalheiro
Copy link

Hey! Any Idea when will this be released at npm? @icambron

Amazing work btw 🚀

jackkoppa added a commit to jackkoppa/DefinitelyTyped that referenced this pull request Jan 4, 2024
jackkoppa added a commit to jackkoppa/DefinitelyTyped that referenced this pull request Jan 4, 2024
jackkoppa added a commit to jackkoppa/DefinitelyTyped that referenced this pull request Jan 4, 2024
jackkoppa added a commit to jackkoppa/DefinitelyTyped that referenced this pull request Jan 4, 2024
jackkoppa added a commit to jackkoppa/DefinitelyTyped that referenced this pull request Jan 4, 2024
typescript-bot pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Jan 5, 2024
* Add missing opts + useLocaleWeeks param to luxon methods

Covers changes added in this luxon PR: moment/luxon#1454

* Rename BaseComparisonOptions to be a more private helper

* Add new luxon Info methods for weekdays

* Add new weekday functionality to DateTime

* Update luxon version to match latest NPM publish

---------

Co-authored-by: Jack Koppa <hello@jackkoppa.com>
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.

Support Intl start of week settings
3 participants