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

Function timeStr2Obj

lib/util/time.js:9–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7var MAX_SEC = MAX_MIN;
8
9var timeStr2Obj = function timeStr2Obj() {
10 var value = arguments.length <= 0 || arguments[0] === undefined ? '00:00:00' : arguments[0];
11 var options = arguments.length <= 1 || arguments[1] === undefined ? {
12 simple: false
13 } : arguments[1];
14
15 value = (0, _typeCheck.isType)(value, 'String') ? value : '00:00:00';
16 var arr = value.split(':').slice(0, 3);
17 var new_arr = [];
18
19 for (var i = 0; i < arr.length; i++) {
20 var item = String(arr[i]);
21 if (item.length > 2) item = item.slice(0, 2);
22 if (item.length === 1) item = '0' + item;
23 if (!item) item = '00';
24 new_arr.push(item);
25 }
26
27 var hour = new_arr[0];
28 var min = new_arr[1];
29 var sec = new_arr[2];
30
31 hour = validateUnitByMax(hour, MAX_HOUR);
32 min = validateUnitByMax(min, MAX_MIN);
33
34 if (options.simple) return { hour: hour, min: min };
35
36 sec = validateUnitByMax(sec, MAX_SEC);
37
38 return { hour: hour, min: min, sec: sec };
39};
40
41var validateUnitByMax = function validateUnitByMax(value, max) {
42 value = String(parseInt(value));

Callers 2

TimeInput.jsFile · 0.50
time-test.jsFile · 0.50

Calls 1

validateUnitByMaxFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…