- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.js
More file actions
Latest commit
44 lines (36 loc) · 1.5 KB
/
Copy pathutils.js
File metadata and controls
44 lines (36 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
varprettyMs=require('pretty-ms');
varmoment=require('moment');
exports.parseStrToMomentOrUndefined=function(input){
returninput!==undefined&&moment(input).isValid() ? moment(input) : undefined;
}
exports.solveValidator=function(min_solve,max_solve,before_timestamp,after_timestamp){
returnfunction(solve_time,solve_unix_ts){
varsolveTimeValid=(!isNaN(solve_time)&&solve_time>=min_solve&&solve_time<=max_solve);
varsolveTsExists=!isNaN(solve_unix_ts)&&typeofsolve_unix_ts==='number'&&solve_unix_ts>0;
varinputOptionsValid=before_timestamp!==undefined||after_timestamp!==undefined;
// Solve time itself is invalid
if(!solveTimeValid){
returnsolveTimeValid;
}
// --after or --before not provided, so timestamp validity needn't be checked
if(!inputOptionsValid){
returnsolveTimeValid;
}
// User has provided --after or --before, solves without timestamps will not be included in
// the statistics
if(inputOptionsValid&&!solveTsExists){
returnfalse;
}
varsolve_moment=moment.unix(solve_unix_ts);
if(before_timestamp===undefined){
returnsolve_moment.isAfter(after_timestamp);
}
if(after_timestamp===undefined){
returnsolve_moment.isBefore(before_timestamp);
}
returnsolve_moment.isBetween(after_timestamp,before_timestamp);
};
}
exports.prettifyVerbose=function(ms){
returnprettyMs(ms,{verbose: true,secDecimalDigits: 2});
}