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

Adding days across daylight savings does not work as expected #586

Closed
denchen opened this issue May 4, 2019 · 7 comments · Fixed by #590
Closed

Adding days across daylight savings does not work as expected #586

denchen opened this issue May 4, 2019 · 7 comments · Fixed by #590
Labels
☢️Bug Something isn't working 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt released

Comments

@denchen
Copy link

denchen commented May 4, 2019

Issuehunt badges

Describe the bug
I'm seeing a weird issue with using add() along with utc() across a daylight savings boundary where it doesn't add a full day.

Expected behavior
Given the following code:

var dayjs = require('dayjs');
var utc = require('dayjs/plugin/utc');
dayjs.extend(utc);

let testDate = dayjs('2019-03-10')
  .utc()
  .startOf('day');
console.log('TESTDATE: ', testDate.format());
let testDate2 = testDate.add(1, 'day');
console.log('TESTDATE2:', testDate2.format());

I expect it to output the following:

TESTDATE:  2019-03-10T00:00:00Z
TESTDATE2: 2019-03-11T00:00:00Z

Instead I see this:

TESTDATE:  2019-03-10T00:00:00Z
TESTDATE2: 2019-03-10T23:00:00Z

Replication here: https://runkit.com/accelerate/runkit-dayjs-daylight-savings

NOTE: I tested the same code with MomentJS and do get the expected behavior.

Information

  • Day.js: 1.8.13
  • OS: MacOS 10.14.4
  • Chrome: 74.0.3729.108

IssueHunt Summary

iamkun iamkun has been rewarded.

Backers (Total: $100.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

@denchen denchen changed the title Adding days across daylight savings Adding days across daylight savings does not work as expected May 4, 2019
@iamkun
Copy link
Owner

iamkun commented May 6, 2019

Your timezone, please? I can't get this reproduced.

@denchen
Copy link
Author

denchen commented May 6, 2019

GMT-07:00 DST (Pacific Daylight Time)

@iamkun iamkun added the ☢️Bug Something isn't working label May 6, 2019
@iamkun
Copy link
Owner

iamkun commented May 6, 2019

Should be a bug related to UTC plugin and core bundle, investigating.

@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label May 7, 2019
@IssueHuntBot
Copy link

@IssueHunt has funded $100.00 to this issue.


@iamkun
Copy link
Owner

iamkun commented May 7, 2019

🎉 This issue has been resolved in version 1.8.14 🎉

The release is available on:

Your semantic-release bot 📦🚀

@iamkun iamkun added the released label May 7, 2019
@issuehunt-oss
Copy link

issuehunt-oss bot commented Aug 12, 2019

@iamkun has rewarded $90.00 to @iamkun. See it on IssueHunt

  • 💰 Total deposit: $100.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $10.00

@issuehunt-oss issuehunt-oss bot added 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt and removed 💵 Funded on Issuehunt This issue has been funded on Issuehunt labels Aug 12, 2019
@bbecker-te
Copy link

bbecker-te commented Feb 14, 2023

I think that some variant of this bug still may be happening. I am using version 1.11.6 of dayjs.

I have a simple test case for what I think is a dayjs bug. I add 2 days to a day in GMT/UTC timezone and get something that is not on a day boundary. It probably has something to do with daylight savings time because this is when daylight savings time happens in US. However, why its it a 2 hour difference, and why does it happen in GMT/UTC time? This change did not happen when we used moment.js.

it('should be exactly two days later when adding two days', function () {
    const day1 = dayjs.tz({ year: 2018, month: 2, day: 10 }, 'GMT');
    const day2 = day1.add(2, 'day');
    expect(day2.valueOf()).toEqual(dayjs.tz({ year: 2018, month: 2, day: 12, hour: 2 }, 'GMT').valueOf());
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️Bug Something isn't working 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants