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

is there an UTC mode? #249

Closed
d2bit opened this issue Jun 21, 2018 · 9 comments · Fixed by #517
Closed

is there an UTC mode? #249

d2bit opened this issue Jun 21, 2018 · 9 comments · Fixed by #517
Labels

Comments

@d2bit
Copy link

d2bit commented Jun 21, 2018

The problem I had is the following. As I'm using CEST timezone the system changes from summer time to winter time (daylight saving time), and I get unexpected results when adding time to my dayjs object.
moment has an UTC mode to set the timezone.

I also found that by default moment does this right
I've attached a failing test. That shows that dayjs is doing different than moment.

test('adding 1 day before changing to daylight summer time', () => {
  const dayBeforeSummerTime = '2018-10-28'

  expect(dayjs(dayBeforeSummerTime).add(1, 'day')).toEqual(moment(dayBeforeSummerTime).add(1, 'day'))
})

Edit j1481qw073

I'll be glad to help if I can.
Thanks in advance

@iamkun
Copy link
Owner

iamkun commented Jun 22, 2018

@d2bit

Daylight saving time is new to me, I'll check it.

And for UTC mode, we are working on is, PR #168

Code review or PR is welcome.

@0xsven
Copy link

0xsven commented Jul 20, 2018

Just stumbled upon this. My date picker has '2018-10-28' twice. xD

My solution for now is:

const nextDay = dayjs('2018-10-28')
          .add(1, 'hours') // to circumvent an issue with dayjs that occurs on 2018-10-28
          .add(1, 'day')
          .format('YYYY-MM-DD')

EDIT: For some reason .add(1, 'second') already does the trick?

@neuronetio
Copy link

neuronetio commented Aug 1, 2018

@0xsven you can't just add an hour to get proper date because sometimes you must add and sometimes you must remove hour depend on summer time or winter time.
On summer clocks are set to -1hour and on winter clocks are set to +1hour.
So sometimes we have (european union) utc+1 and sometimes we have utc+2

@0xsven
Copy link

0xsven commented Aug 1, 2018

@neuronetio
In my use case (a day picker) I only need the day to be correct.

Also: for some reason, already adding one second solved the problem for me.

@prantlf
Copy link
Contributor

prantlf commented Sep 5, 2018

@d2bit, @0xsven, @neuronetio, you initialised the dayjs object with a full local time. You need to remember it, when you're adding or subtracting to/from it.

Your scenario is a "date-only" object. The time part is not relevant. However, JavaScript has no DateOnly or Date.prototype.dateOnly = true. The Date object always includes time and expects the local time zone by default, although you sent only the date part to the constructor by "2018-10-28". You get the time set too, for example to 1:00 in Berlin. If you miss this, you will be in trouble. Knowing this will allow you to use Day.js without problems. I am an EU citizen too :-)

Yes, it may not be obvious, that the time part is always there, when you call dayjs("2018-10-28"). However, this is consistent with new Date("2018-10-28") and thus not confusing and easy to remember.

Day.js could offer an UTC mode, so that if you initialise the dayjs object with UTC, the day will not be converted to the local time zone. But again, remembering how you initialised the object is crucial. Offering a date-only mode would make this scenario clearer.

@ghost
Copy link

ghost commented Sep 26, 2018

@neuronetio this lib supports DST since v1.7.7

Repository owner deleted a comment from neuronetio Feb 24, 2019
@iamkun
Copy link
Owner

iamkun commented Mar 5, 2019

DST already supported

@iamkun
Copy link
Owner

iamkun commented Mar 6, 2019

🎉 This issue has been resolved in version 1.8.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

@iamkun iamkun added the released label Mar 6, 2019
bludnic added a commit to Adamant-im/adamant-im that referenced this issue Mar 25, 2019
- remove moment-timezone dependency
- remove ChatPreview & TransactionListItem snapshots because dayjs does
not support UTC iamkun/dayjs#249
@iamkun
Copy link
Owner

iamkun commented Feb 22, 2020

Yes, please check.

https://day.js.org/docs/en/parse/utc

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

Successfully merging a pull request may close this issue.

5 participants