question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

startOf('week') is not respecting locale setting

See original GitHub issue

While most countries in the world assume the week starts on Monday, US, Canada, and Australia consider Sunday as the first day of the week. It seems that luxon hard-coded the start of week as Monday.

// prints "2018-11-19T00:00:00.000-08:00"
console.log(DateTime.fromISO('2018-11-22T10:00', {zone: 'America/Los_Angeles'}.startOf('week').toISO());

Note that moment does actually respect the locale setting

// prints "2018-11-18T08:00:00.000Z"
console.log(moment.tz('2018-11-22T10:00', "America/Los_Angeles").startOf('week').toISOString());

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
lostdesigncommented, Sep 16, 2021

While this is a quite old issue, I still wanted to share my quick work around:

const date = DateTime.fromISO('2021-09-16').startOf('week')
const sunday = date.minus({day: 1})

By simply subtracting a day, you get a sunday which you can use as a start point for further actions.

edit: However, once possible, this should be part of the API.

6reactions
dasacommented, Jul 22, 2021

As far as I know, there’s no Intl API I can use to get the local first day of the week.

It’s coming soon: https://chromestatus.com/feature/5566859262820352

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create momentLocaleData.firstDayOfWeek() in luxon?
I fear that, at the moment (current version 2.4.0 ), it is not possible achieve this using Luxon. The Luxon 1.x docs states:....
Read more >
Calendar doesn't respect start of week setting from google ...
Set start of week in http://calendar.google.com settings to Monday. 2. I have a repeating every 3 week Monday-Sunday all day event. Monday 17th...
Read more >
Day of Week (Locale Aware)
Gets or sets the day of the week according to the locale. This dependent on Weekday plugin to work. If the locale assigns...
Read more >
week set to Sunday despite having Spain (Monday) as Locale
Despite having set the locale the either UK or Spain, the function is considering sunday as the start of the week and, hence,...
Read more >
How to find first day of the week by locale?
Simply use the LWC I18N functionality: import firstDayOfWeek from '@salesforce/i18n/firstDayOfWeek';.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found