Coder Social home page Coder Social logo

Comments (5)

illright avatar illright commented on August 11, 2024

Cannot reproduce on desktop/mobile Chrome and on Firefox. Could you tell me what's your browser and system locale?

from attractions.

sallaben avatar sallaben commented on August 11, 2024

Mozilla/5.0, Gecko/20100101 Firefox/85.0 -- for what it's worth, I can reproduce on mobile (Safari). Maybe it's a locale based bug? I'm in USA

from attractions.

aabounegm avatar aabounegm commented on August 11, 2024

I also couldn't reproduce on Firefox 84 or 85.0.2, and my locale is also set to en-US. I have no access to Safari to test it there, though.

from attractions.

sallaben avatar sallaben commented on August 11, 2024

Very interesting, thanks for the comments guys... I looked deeper into the calendar component and datetime utils, and the main issue boils down to the setMonth functionality on JS Date.

  const foo = new Date(0);
  foo.setFullYear(2021, 1); // setMonth is used by setFullYear implementation as well
  console.log(foo);

We expect this return a Date object for February 1st, and when I run this code in a UTC node container, I get the expected result: 2021-02-01T00:00:00.000Z. But when I run the exact same code locally in node (15.8.0) or in my browser, the result is 2021-03-04T00:00:00.000Z.

First: I'm thinking maybe the way we create the day cursor, using new Date(0), is failing in non UTC environments (I am in Mountain Standard Time). But this should only account for at maximum 1 day difference.

Here's the other problem, from what I understand. When the date is, for example, January 31 2021, and we setMonth to February, it becomes February 31 2021 -- which then becomes sometime in the first week of March 2021, since there is no February 31. This messes up the rest of getCalendar logic downstream.

  • Here are two StackOverflow questions about this topic. 1 2

I have identified a fix for these behaviors. When using setMonth or setFullYear to change the month value, ensure that we also pass a date value in at the same time. Also create day cursor using new Date() and not new Date(0).

  • Here is a PR to fix the behavior in the datetime-utils: #244

And February now displays normally :-) ...Sorry, I am a MM.DD.YYYY weirdo.
image

from attractions.

aabounegm avatar aabounegm commented on August 11, 2024

It was confusing to me how these links are relevant when the date today is the 15th (or 14th for you), and especially that new Date(0) should return the epoch (1970.01.01), irrelevant of the current timezone (I was wrong!). Turns out that the timezone actually affects even that constructor, so I tried changing my timezone to US/Pacific (the one available in DevTools) and running new Date(0), and it indeed gave me 1969.12.31!
Thank you for pointing this out, I'll review the PR now.

P.S.: I can get used to MM.DD.YYYY, but I've never seen a locale where the week starts on Friday!

from attractions.

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.