Giter VIP home page Giter VIP logo

Comments (10)

JeanMeche avatar JeanMeche commented on May 10, 2024 1

Yes, I have a pending PR at #53879, we'll test it against Google's codebase to see how breaking the fix is consideredd !

from angular.

chucknelson avatar chucknelson commented on May 10, 2024

FYI added a link to a reproduction in StackBlitz - just the simple code that generates the table in the description screenshot.

from angular.

JeanMeche avatar JeanMeche commented on May 10, 2024

Quick investigation, this issue happens every year where Dec 31st is a sunday.
Looks like there is a bug in our algorithm.

from angular.

JeanMeche avatar JeanMeche commented on May 10, 2024

It looks like to boil down to: What do we consider the start of the week ?

Should it be sunday like in the US ? Or should it be monday like defined by ISO 8106.
Angular currently implements the former.

Repro : https://stackblitz.com/edit/angular-zcyztw?file=src%2Fmain.ts

from angular.

JeanMeche avatar JeanMeche commented on May 10, 2024

Also I wanted to add about this topic:

I believe the definition of the week numbering year / end of week is unclear in the framework : Is it ISO based or Locale based ?

In the case of date-fns, it has 2 functions getISOWeek() and getWeek(). The Former is ISO based while the latter is Locale based. luxon has the same distinctions : kkkk is the ISO week year, iiii is the locale week year.

In both cases Angular has a bug, the concept of week is neither locale based (the dedicated function doesn't rely on a locale or the dedicated function we have getLocaleFirstDayOfWeek) nor ISO based (is assumes the week starts on Sunday).

from angular.

chucknelson avatar chucknelson commented on May 10, 2024

Thanks @JeanMeche for looking into this.

Good catch on the "local" vs "ISO" week year - I didn't even notice local options in formatting and assumed week years was entirely from an ISO perspective.

  • Using the "local week numbering year" in both date-fns and luxon matches what DatePipe is doing if I use the US locale (which is where I am) - which makes sense considering you're saying Angular is using the US-type definition of "start of week = Sunday".
  • Using other locales like French (👍), though, matches the ISO week year as expected, since the start of the week is Monday.

Not that I have much say in how you all proceed, but I guess it seems like Angular is all about honoring the locale of the browser/system, so maybe defaulting to "local" week behavior for day of week, week number and week-numbering year makes the most sense?

I guess it would make sense to have formatting string options for both the "local" and "ISO" week items also?

from angular.

chucknelson avatar chucknelson commented on May 10, 2024

Maybe I spoke to soon - it looks like there is still a discrepancy in how date-fns and luxon handle local week years versus DatePipe.

Added the local week year's to the repro link, and right in 2020 you can see they differ from the DatePipe...but I was thinking since Angular was assuming Sunday as the start of week, they'd match. 🤔

image

Also discovered another online tool that works well for ad-hoc comparison of the "local" vs "ISO" week numbers and years: https://www.calendar-12.com/week_number. Basically let's you see the "north american" version where the week starts on Sunday, vs the "ISO"/everyone else version where the week starts on Monday.

from angular.

JeanMeche avatar JeanMeche commented on May 10, 2024

Supposing you're in the US, you locale is en-US.

For this locale, if at least 1 day of the week is the next year, the week is from next year (new Intl.Locale('en-US').weekInfo.minimalDays on Chrome browsers, or check the CLDR).

So for locale week year this is correct (and anguar is wrong by mixin ISO (thursday bases the weekyear) and week starting on Sunday).

from angular.

chucknelson avatar chucknelson commented on May 10, 2024

@JeanMeche Thanks again. So it sounds like you have all the info you need to adjust how Angular is calculating ISO weeks and week years?

from angular.

angular-automatic-lock-bot avatar angular-automatic-lock-bot commented on May 10, 2024

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

from angular.

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.