forked from yoshhiide/time-range
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
34 lines (28 loc) · 1.02 KB
/
example.js
File metadata and controls
34 lines (28 loc) · 1.02 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
'use strict';
const timeRange = require('./lib/time-range');
//const timeRange = require('time-range');
// range calc
const times = [
[ new Date(2017, 3, 24, 10, 10, 0), new Date(2017, 3, 25, 2, 10, 30) ],
[ new Date(2017, 3, 24, 20, 20, 0), new Date(2017, 3, 25, 2, 10, 30) ],
[ new Date(2017, 3, 24, 22, 30, 0), new Date(2017, 3, 25, 2, 10, 30) ],
[ new Date(2017, 3, 24, 23, 40, 0), new Date(2017, 3, 25, 2, 10, 30) ],
];
console.log( 'total minutes = ' + timeRange.calc(times) );
console.log( 'total seconds = ' + timeRange.calc(times, 'seconds') );
// overlap check
const times2 = [
[ new Date(2017, 3, 24, 10, 10, 0), new Date(2017, 3, 25, 2, 10, 30) ],
[ new Date(2017, 3, 25, 2, 10, 29), new Date(2017, 3, 25, 2, 30, 30) ],
];
if (timeRange.overlap(times2)) {
console.log( 'not overlap.' );
} else {
console.log( 'overlap or bad case.' );
}
// valid date in array
if (!timeRange.validDateArray(times) || !timeRange.validDateArray(times2)) {
console.log( 'not date in array' );
} else {
console.log( 'all date' );
}