File tree 2 files changed +5
-3
lines changed
tests/unit/services/parsing
2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change 3
3
* Examples: PT40M25S
4
4
*/
5
5
export function parseIso8601Duration ( duration : string ) : number {
6
- let match = / P ( \d + D ) ? (?: T ( \d + H ) ? ( \d + M ) ? ( \d + S ) ? ) ? /
6
+ let match = / P ( \d + D ) ? (?: T ( \d + H ) ? ( \d + M ) ? ( [ \d . ] + S ) ? ) ? /
7
7
. exec ( duration )
8
8
?. slice ( 1 )
9
9
. map ( x => {
10
10
if ( x !== null && x !== undefined ) {
11
- return x . replace ( / \D / , "" ) ;
11
+ return x . replace ( / [ ^ \d . ] / , "" ) ;
12
12
}
13
13
} ) ;
14
14
@@ -19,7 +19,7 @@ export function parseIso8601Duration(duration: string): number {
19
19
const days = parseInt ( match [ 0 ] ?? "0" , 10 ) || 0 ;
20
20
const hours = parseInt ( match [ 1 ] ?? "0" , 10 ) || 0 ;
21
21
const minutes = parseInt ( match [ 2 ] ?? "0" , 10 ) || 0 ;
22
- const seconds = parseInt ( match [ 3 ] ?? "0" , 10 ) || 0 ;
22
+ const seconds = parseFloat ( match [ 3 ] ?? "0" ) || 0 ;
23
23
24
24
return days * ( 24 * 3600 ) + hours * 3600 + minutes * 60 + seconds ;
25
25
}
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { parseIso8601Duration } from "../../../../services/parsing/iso8601";
3
3
describe ( "parse iso8601 duration" , ( ) => {
4
4
it . each ( [
5
5
[ "PT10S" , 10 ] ,
6
+ [ "PT10.0S" , 10 ] ,
7
+ [ "PT10.000S" , 10 ] ,
6
8
[ "PT5M" , 5 * 60 ] ,
7
9
[ "PT40M25S" , 40 * 60 + 25 ] ,
8
10
[ "PT1H" , 1 * 60 * 60 ] ,
You can’t perform that action at this time.
0 commit comments