-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 format result is not as expected #1521
Comments
Did you take a look at this issue ? Dou you need more test case ? |
I'm actually having a similar issue with the above problem with regards to Upon inspecting the code here: dayjs/src/plugin/duration/index.js Lines 83 to 100 in 5a79cc6
Which uses the regex: dayjs/src/plugin/duration/index.js Line 13 in 5a79cc6
It appears that there are multiple issues with regards to parsing ISO 8601 duration strings. The first is that some capture groups will not always be present as defined by ISO 8601, resulting in const input = 'PT3H19M';
const regex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
const found = input.match(regex);
console.log(found);
// > Array ["PT3H19M", undefined, undefined, undefined, undefined, undefined, "3", "19", undefined] The second issue is that the regex for seconds will capture both integers and decimals. When converted to a Number, the decimal will be kept when the duration object |
I've just hit this problem and I've found that calling |
🎉 This issue has been resolved in version 1.10.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hello, @cypressious & @iamkun , thanks a lot for your action, but new issue #1665 is open for complet solve this |
Describe the bug
When use duration format for an ISO8601, result it's not as expected :
myDuration = dayjs.duration('PT3M39.096S')
myDuration.format("HH:mm:ss") => "NaN:03:39.096"
myDuration.format("mm:ss") => "03:39.096"
myDuration.format("ss") => "39.096"
myDuration.format("SSS") => "undefined"
Expected behavior
myDuration.format("HH:mm:ss") => "00:03:39"
myDuration.format("mm:ss") => "03:39"
myDuration.format("ss") => "39"
myDuration.format("SSS") => "096"
Information
The text was updated successfully, but these errors were encountered: