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
duration.valueOf() shall return number of milliseconds #1274
Comments
This would be problematic for some cases, where additional context is needed: // Months have 28 to 31 days
dayjs.duration(1, 'month').valueOf()
// Minutes can include leap seconds
dayjs.duration(1, 'minute').valueOf()
// Years can include leap days
dayjs.duration(1, 'year').valueOf() |
if dayjs.duration(1, 'month').valueOf() has problem, dayjs.duration(1, 'month').asMilliseconds() would have same problem. So I didn't see where is problem besides apparently breaking change |
I agree with adding a Moment's duration has a @franky47 Regarding your comment, I don't think the Even Moment.js has this issue with it's duration. See here for more information: https://momentjs.com/docs/#/durations/. They make a reasonable assumption as to the length of a month & year and go from there. If anyone is interested, here's code for extending the Day.js duration to add a // What a wonderful hack because Day.js decides NOT to export the Duration class
const Duration = dayjs.duration(0, 'ms').constructor;
Duration.prototype.equals = function(other: dayjs.Duration) {
return this.$ms === (other as any).$ms;
};
// valueOf is used for comparison between durations
Duration.prototype.valueOf = function() {
// Return total number of ms
return this.$ms;
}; |
Describe the bug
javascript convention is valueOf() shall return comparable value
Expected behavior
above script shall print true, however, false would be printed
Information
The text was updated successfully, but these errors were encountered: