Skip to content

day1co/time-range

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TimeRange

time range functions

Installation

$ npm install --save time-range

Usage

'use strict';

const timeRange = require('time-range');

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) );
// total minutes = 1682

console.log( 'total seconds = ' + timeRange.calc(times, 'seconds') );
// total seconds = 100920

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' );
}

LICENSE

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%