Skip to content
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

Doesn't add day #329

Closed
LexSwed opened this issue Sep 6, 2018 · 6 comments
Closed

Doesn't add day #329

LexSwed opened this issue Sep 6, 2018 · 6 comments

Comments

@LexSwed
Copy link

LexSwed commented Sep 6, 2018

Version:1.7.5
Wasn't reproducible on version 1.6.x (don't remember now)
Similar issue to: #262

Trying to add day to 28 of October 2018 doesn't add anything:
https://codepen.io/lexswed/pen/NLaRZY

console.log(dayjs('2018-10-28').format('MMM dd DD'))
console.log(dayjs('2018-10-28').add(1, 'day').format('MMM dd DD'))

image

@rajdee
Copy link

rajdee commented Sep 7, 2018

@LexSwed I can't reproduce this issue
image

@brendanalexdr
Copy link

brendanalexdr commented Sep 9, 2018

I'm getting this exact same issue. Maybe has something to do with daylight savings. From googling "sunday 28th october clocks":

In the UK the clocks go forward 1 hour at 1am on the last Sunday in March, and back 1 hour at 2am on the last Sunday in October. The period when the clocks are 1 hour ahead is called British Summer Time (BST). There's more daylight in the evenings and less in the mornings (sometimes called Daylight Saving Time).

Can confirm that this bug occurs every year on last Sunday of October. And I'd guess that same error would occur on the last Sunday of march if subtracting a day from the first Monday of March.

@brendanalexdr
Copy link

The following is a very hackie solution. But it works for now until this is fixed.

  const dtm_ = dtm.clone(); 
    dtm = nkFn.dtm.trimDate(dtm.add(1, "day"));
    if (dtm_.isSame(dtm)) {

      dtm = nkFn.dtm.trimDate(dtm_.add(2, "day"));  // forces going to the next day

    }      

nkFn.dtm.trimDate is just a custom function to make hours/mins/seconds = 0

@prantlf
Copy link
Contributor

prantlf commented Sep 13, 2018

@LexSwed, you need to consider the fact, that dayjs works in the local time zone by default, just like Date. There are PRs #168 and #326 to introduce a "UTC mode" which will allow work with an apparent "date-only" value, which you use in your case.

Your case is similar to #262, #249 and #74.

When you constructed the dayjs instance like this:

dayjs('2018-10-28')

you assumed, that it works like a "date-only" instance. After adding 1 day, you expected it to become like dayjs('2018-10-28'). However, it was wrong. Both dayjs and Date assumed, that you supplied a string in UTC and you just omitted the time part. You actually performed the following initialization:

dayjs('2018-10-28T00:00:00Z')

It means, that you have a full date+time object. Both dayjs and Date work in the local time zone by default, which you can confirm by using getters, setters and toString. The actually stored value will be this in Central Europe:

2018-10-28 01:00:00 GMT+01:00 (CET)

Depending on DST changes in your local time zone, adding or subtracting a day may result in an hour shift, which may affect your day value. If you want to prevent it, you need to use setters with UTC in their name, when working with Date. When working with dayjs you can do nothing, because there are no UTC-setters there yet. You workaround will work, or you can try the UTC mode from the PRs.

@brendanalexdr
Copy link

I like dayjs quite a bit. But had to move to Luxon to feel confident there wasn't something buggie going on every year on last Sunday of October.

@iamkun iamkun closed this as completed in 969aced Sep 26, 2018
@iamkun
Copy link
Owner

iamkun commented Sep 26, 2018

@nukuuk @LexSwed You may could try v1.7.7 and check if this issue is fixed in your timezone. THX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants