Comments (7)
Does Settings.defaultWeekSettings
cover your use case?
from luxon.
Does
Settings.defaultWeekSettings
cover your use case?
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.
from luxon.
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.
If the user works with different locales, you can still have separate DateTime
instances with separate locales. If you generally just want "the last Saturday", that's not really "start of the week", it's just something you'll have to implement.
Although Luxon could theoretically provide a lastWeekday(X)
and nextWeekday(X)
API.
from luxon.
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.
from luxon.
Although Luxon could theoretically provide a lastWeekday(X) and nextWeekday(X) API.
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.
from luxon.
My only concern is that startOf
is not the only place where startOfWeek
is used. So, if we were to add this option, it would have to be added everywhere where startOfWeek
is used. Some of those places are just getters (DateTime#localeWeekYear
for example), so it would have to be done completely differently in that case.
What could be done is to expose more fine-grained locale configuration, i.e. provide a way to create a DateTime
with locale en-US
, but override the locale's startOfWeek
for that DateTime only. In that case I can imagine other locale options being overridable as well.
from luxon.
Related Issues (20)
- Question: Global settings default locale, will it override the settings for simultaneous requests? HOT 1
- แนะนําสําหรับผู้เริ่มต้น
- Settings.defaultWeekSettings not working HOT 1
- Duration.toFormat does not display milliseconds correctly HOT 1
- fromFormat parsing fails on productions, works on development HOT 2
- **Describe the bug**
- This is blocked by the fact that the PHP library is outdated.
- Persian Calendar with Luxon HOT 1
- Incorrect weekNumber on Sundays HOT 2
- Adapter islamic and persian
- Able to pass invalid localWeekNumber
- DateTime.fromISO() returns invalid date for (some) numbers
- Timezone 'CST' is unsupported in Firefox browser HOT 1
- `twoDigitCutoffYear` not working as expected HOT 1
- Luxon fails to parse ISO 8601 date with 'Z' suffix as UTC HOT 1
- can't get week day index from UTC date HOT 2
- Property 'now' does not exist on type 'typeof DateTime'. HOT 1
- Wrong Time coming for Asia/Almaty timezone HOT 1
- Luxon seems incredibly illogical HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luxon.