1 function timeUnitToSeconds(value
, unit
)
16 function isLargerUnit(unit1
, unit2
)
18 return (unit1
== 'd' && unit2
!= 'd')
19 || (unit1
== 'h' && ['s','m'].includes(unit2
))
20 || (unit1
== 'm' && unit2
== 's');
23 export function extractTime(cadence
)
25 let tcParts
= cadence
.replace(/ /g
,"").split('+');
26 // Concatenate usual time control suffixes, in case of none is provided
29 const mainTimeArray
= tcParts
[0].match(/([0-9]+)([smhd]+)/);
32 const mainTimeValue
= parseInt(mainTimeArray
[1]);
33 const mainTimeUnit
= mainTimeArray
[2][0];
34 const mainTime
= timeUnitToSeconds(mainTimeValue
, mainTimeUnit
);
36 if (tcParts
.length
>= 2)
38 const incrementArray
= tcParts
[1].match(/([0-9]+)([smhd]+)/);
41 const incrementValue
= parseInt(incrementArray
[1]);
42 const incrementUnit
= incrementArray
[2][0];
43 // Increment unit cannot be larger than main unit:
44 if (isLargerUnit(incrementUnit
, mainTimeUnit
))
46 increment
= timeUnitToSeconds(incrementValue
, incrementUnit
);
48 return {mainTime:mainTime
, increment:increment
};