Initial commit: Upload Checkpoint project
This commit is contained in:
commit
c0e3781244
32 changed files with 6121 additions and 0 deletions
20
utils/time.js
Normal file
20
utils/time.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
export function parseDuration(str) {
|
||||
if (!str) return 0;
|
||||
const m = /^([0-9]+)(ms|s|m|h|d)$/.exec(str);
|
||||
if (!m) return 0;
|
||||
const val = parseInt(m[1], 10);
|
||||
switch (m[2]) {
|
||||
case 'ms':
|
||||
return val;
|
||||
case 's':
|
||||
return val * 1000;
|
||||
case 'm':
|
||||
return val * 60 * 1000;
|
||||
case 'h':
|
||||
return val * 60 * 60 * 1000;
|
||||
case 'd':
|
||||
return val * 24 * 60 * 60 * 1000;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue