Coder Social home page Coder Social logo

Comments (7)

diesieben07 avatar diesieben07 commented on June 8, 2024

Does Settings.defaultWeekSettings cover your use case?

from luxon.

jasonmobley avatar jasonmobley commented on June 8, 2024

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.

diesieben07 avatar diesieben07 commented on June 8, 2024

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.

jasonmobley avatar jasonmobley commented on June 8, 2024

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.

jasonmobley avatar jasonmobley commented on June 8, 2024

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.

diesieben07 avatar diesieben07 commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.