-
Notifications
You must be signed in to change notification settings - Fork 729
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 optional startOfWeek param for startOf() and endOf() methods #1573
Comments
Does |
Sort of, but only if the user is always working in the context of a single instance of that entity that has startDayOfWeek, which is generally true in my app. But then I'm relying on that assumption, and I'd have to keep re-configuring that setting as the user moves around within the app. It'd be easier if I could specify at the time I need a startOf('week') or an endOf('week') that I think weeks start on Saturdays, or Mondays, or whatever. |
I don't know your application, but to me this sounds like you're not really talking about "weeks". The concept of "week" doesn't change depending on what you are working on. In the en-US locale, a week always starts on a Sunday. Although Luxon could theoretically provide a |
Maybe my use case is too specific and not something that Luxon should support. It just seems like a small specialization of the current behavior (use this exact value as startDayOfWeek instead of reading it from a setting). To give a bit more context, one of the main features of the app is managing employee work schedules, which are 1 to 6 weeks long. So, we are definitely dealing in real weeks and real calendar concepts. Each schedule exists within an entity that has (among other things) a configurable start day of week. |
I thought about this too, but the semantics are a little different in some cases. For example if today is Monday and startDayOfWeek is Monday, then I expect startOf('week') to give me today's date. Many people would reasonably expect giveMeTheLast(Monday) to give the prior Monday, not today's date, whereas startOf isn't ambiguous like that. |
My only concern is that What could be done is to expose more fine-grained locale configuration, i.e. provide a way to create a |
Our app requires the same kind of behavior. Currently I keep switching between settings which looks like this: const oldSettings = {...Settings.defaultWeekSettings};
const newSettings = weekStartsOnToInt(weekStartsOn);
Settings.defaultWeekSettings = newSettings;
const result = KeepingDateTime.fromObject(date.toObject()).startOf('week', {useLocaleWeeks: true});
Settings.defaultWeekSettings = {...newSettings, ...oldSettings};
return result; Having the option to define the week settings on a |
In our app, the start day of week is a configurable property of an entity in our data model. When working with data related to that entity, we show calendar and schedule data relative to that start day of week regardless of locale settings.
I'd like to specify the weekday number that I consider the first day of the week when calling
DateTime.startOf('week')
orDateTime.endOf('week')
similar to the existinguseLocaleWeeks
option.Alternatives I've consider: implement this myself outside of Luxon :)
Example:
The text was updated successfully, but these errors were encountered: