question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Version:1.7.5 Wasn’t reproducible on version 1.6.x (don’t remember now) Similar issue to: https://github.com/iamkun/dayjs/issues/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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
iamkuncommented, Sep 26, 2018

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

1reaction
prantlfcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MS Project 2013 Can't add 'days' correctly
MS Project 2013 Can't add 'days' correctly. When I set duration to '2 days' the calendar advances only 1 day.
Read more >
3 Ways to Add or Subtract Days to a Date - Excel Campus
Learn 3 different ways to add or subtract days to dates in Excel using formulas, copy & paste, and VBA macros. Includes video...
Read more >
Adding/Subtracting days from a date doesn't change the year ...
I think you meant to do this: (working perfectly) var date = new Date('2011','01','02'); alert('the original date is '+date); var newdate = new...
Read more >
How to add and subtract dates in Excel - Ablebits
See how to quickly subtract or add two dates, add days to a date, add or subtract weeks, months and years, and calculate...
Read more >
How to Add Days to Dates in Excel - YouTube
In this video we look at 3 different ways to add or subtract days to dates in Excel using formulas, ... Your browser...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found