Skip to content

Round off datetime to fixed time interval

License

Notifications You must be signed in to change notification settings

arshadkazmi42/datetime-round

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

datetime-round

Build NPM Version NPM Downloads Github Repo Size LICENSE Contributors Commit

Rounds off datetime to nearest interval

Install

npm i datetime-round

Usage

const DatetimeRound = require('datetime-round');


DatetimeRound(moment('2019-08-30 10:11:25'), 30, 'minutes', 'ceil')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:30:00

DatetimeRound(moment('2019-08-30 10:11:25'), 30, 'minutes', 'floor')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:00:00

DatetimeRound(moment('2019-08-30 10:11:25'), 10, 'minutes', 'ceil')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:20:00

DatetimeRound(moment('2019-08-30 10:11:25'), 10, 'minutes', 'floor')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:10:00

DatetimeRound(moment('2019-08-30 10:11:25'), 5, 'minutes', 'ceil')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:15:00

DatetimeRound(moment('2019-08-30 10:11:25'), 5, 'minutes', 'floor')
  .format('YYYY-MM-DD HH:mm:ss');
// 2019-08-30 10:10:00

Params

DatetimeRound will accept following parameters as input

  • date: String datetime / moment object
  • interval: Time interval till which time needs to be rounded to (integer)
  • intervalType: Type of interval (minutes, hours, seconds)

    Refer to moment.duration docs for all available formats.

  • method: Rounding method, floor, ceil .... (It supports all the round methods available in NodeJS Math package)

Contributing

Interested in contributing to this project? You can log any issues or suggestion related to this library here

Read our contributing guide on getting started with contributing to the codebase

About

Round off datetime to fixed time interval

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 5