1 function timeUnitToSeconds(value
, unit
) {
5 seconds
*= 86400; //24*60*60
17 function isLargerUnit(unit1
, unit2
) {
19 (unit1
== "d" && unit2
!= "d") ||
20 (unit1
== "h" && ["s", "m"].includes(unit2
)) ||
21 (unit1
== "m" && unit2
== "s")
25 export function extractTime(cadence
) {
26 let tcParts
= cadence
.replace(/ /g
, "").split("+");
27 // Concatenate usual time control suffixes, in case of none is provided
30 const mainTimeArray
= tcParts
[0].match(/^([0-9]+)([smhd]+)$/);
31 if (!mainTimeArray
) return null;
32 const mainTimeValue
= parseInt(mainTimeArray
[1]);
33 const mainTimeUnit
= mainTimeArray
[2][0];
34 const mainTime
= timeUnitToSeconds(mainTimeValue
, mainTimeUnit
);
36 if (tcParts
.length
>= 2) {
37 const incrementArray
= tcParts
[1].match(/^([0-9]+)([smhd]+)$/);
38 if (!incrementArray
) return null;
39 const incrementValue
= parseInt(incrementArray
[1]);
40 const incrementUnit
= incrementArray
[2][0];
41 // Increment unit cannot be larger than main unit:
42 if (isLargerUnit(incrementUnit
, mainTimeUnit
)) return null;
43 increment
= timeUnitToSeconds(incrementValue
, incrementUnit
);
45 return { mainTime: mainTime
, increment: increment
};