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

Wrong calculation in fromNow() if February #29 is in range #5398

Open
rafalgiemza opened this issue Feb 28, 2020 · 2 comments
Open

Wrong calculation in fromNow() if February #29 is in range #5398

rafalgiemza opened this issue Feb 28, 2020 · 2 comments

Comments

@rafalgiemza
Copy link

rafalgiemza commented Feb 28, 2020

Describe the bug
Bug occurs in leap year

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/boring-wave-z2x73
  2. Open Table.js
  3. See line with index 3
  4. See in column day '30 days ago'

Expected behavior
Should be 31 days ago

Screenshots
Zrzut-ekranu-2020-02-28-o-18-00-08

Please run the following code in your environment and include the output:

console.log((new Date()).toString())
console.log((new Date()).toLocaleString())
console.log((new Date()).getTimezoneOffset())
console.log(navigator.userAgent)
console.log(moment.version)

console.log output:

new Date().toString() ->  Fri Feb 28 2020 17:58:05 GMT+0100 (czas środkowoeuropejski standardowy) 
new Date().toLocaleString() ->  28.02.2020, 17:58:05 
new Date().getTimezoneOffset() ->  
-60
navigator.userAgent ->  Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36 
moment.version ->  2.24.0 
@Alanscut
Copy link
Contributor

@rafalgiemza Errors not only occur in leap years, they also have problems in non leap years.

Snipaste_2020-04-21_10-57-08

Source Code
There will always be a certain deviation when the number of months and days are converted from each other. Maybe we should return the specific number of days according to the specific month.
Do you have any ideas : )? thanks.

// bubble.js
export function daysToMonths (days) {
    // 400 years have 146097 days (taking into account leap year rules)
    // 400 years have 12 months === 4800
    return days * 4800 / 146097;
}
export function monthsToDays (months) {
    // the reverse of daysToMonths
    return months * 146097 / 4800;
}

@marwahaha
Copy link
Member

Is this a problem in 2.25.3 ?

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

No branches or pull requests

3 participants