MCPcopy Create free account
hub / github.com/flyfloor/react-component / timeStr2Obj

Function timeStr2Obj

component/util/time.js:7–31  ·  view source on GitHub ↗
(value='00:00:00', options = {
    simple: false, 
})

Source from the content-addressed store, hash-verified

5const MAX_SEC = MAX_MIN;
6
7const timeStr2Obj = (value='00:00:00', options = {
8 simple: false,
9}) => {
10 value = isType(value, 'String') ? value : '00:00:00'
11 let arr = value.split(':').slice(0, 3)
12 let new_arr = [];
13
14 for (let i = 0; i < arr.length; i++) {
15 let item = String(arr[i]);
16 if (item.length > 2) item = item.slice(0, 2);
17 if (item.length === 1) item = `0${item}`;
18 if (!item) item = '00';
19 new_arr.push(item);
20 }
21
22 let [hour, min, sec] = new_arr;
23 hour = validateUnitByMax(hour, MAX_HOUR);
24 min = validateUnitByMax(min, MAX_MIN);
25
26 if (options.simple) return { hour, min };
27
28 sec = validateUnitByMax(sec, MAX_SEC);
29
30 return { hour, min, sec };
31};
32
33const validateUnitByMax = (value, max) => {
34 value = String(parseInt(value));

Callers 1

initTimeFunction · 0.50

Calls 2

isTypeFunction · 0.90
validateUnitByMaxFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…