Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create momentLocaleData.firstDayOfWeek() in luxon?

Tags:

luxon

In moment you can call:

momentLocaleData.firstDayOfWeek()

Is it possible to get the same functionality in Luxon?

like image 275
DauleDK Avatar asked May 15 '18 12:05

DauleDK


1 Answers

I fear that, in the lastest version (1.3.3), it is not possible since docs states:

Basic internationalization. Luxon doesn't have internationalized strings in its code; instead it relies on the hosts implementation of the Intl API. This includes the very handy toLocaleString. Most browsers and recent versions of Node support this.

Moreover, using Luxon, you always get Monday as the first day of the week, as you can see in the following snippet:

// Luxon
const DateTime = luxon.DateTime;
console.log( DateTime.local().setLocale('fr-CA').startOf('week').toISO() );
// Moment.js
console.log( moment().locale('fr-ca').startOf('week').format() );
<script src="https://moment.github.io/luxon/global/luxon.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment-with-locales.min.js"></script>

Please note that there is no 'week' parameter in startOf docs:

"Set" this DateTime to the beginning of a unit of time.

Params:

Name    Type    Attribute   Description
unit    string              The unit to go to the beginning of. Can be 'year', 'month', 'day', 'hour', 'minute', 'second', or 'millisecond'.
like image 134
VincenzoC Avatar answered Nov 14 '22 05:11

VincenzoC