89f7f31dd10db83f22e6ddc020531964ada98deb
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(timeControl
)
25 const tcParts
= timeControl
.replace(/ /g
,"").split('+');
26 const mainTimeArray
= tcParts
[0].match(/([0-9]+)([smhd])/);
29 const mainTimeValue
= parseInt(mainTimeArray
[1]);
30 const mainTimeUnit
= mainTimeArray
[2];
31 const mainTime
= timeUnitToSeconds(mainTimeValue
, mainTimeUnit
);
33 if (tcParts
.length
>= 2)
35 const incrementArray
= tcParts
[1].match(/([0-9]+)([smhd])/);
38 const incrementValue
= parseInt(incrementArray
[1]);
39 const incrementUnit
= incrementArray
[2];
40 // Increment unit cannot be larger than main unit:
41 if (isLargerUnit(incrementUnit
, mainTimeUnit
))
43 increment
= timeUnitToSeconds(incrementValue
, incrementUnit
);
45 return {mainTime:mainTime
, increment:increment
};