Skip to content

Plugin for momentjs to round time in dates.

License

Notifications You must be signed in to change notification settings

joinhonor/moment-round

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moment-round

This is a plugin for moment.js and will round date/time to a given interval.

Examples

var m = new moment(); 
m.format( 'YYYY-MM-DD HH:mm:ss.SSS' ); 								// 2015-06-18 15:30:19.123
m.round( 100, 'milliseconds' ).format( 'YYYY-MM-DD HH:mm:ss.SSS' ); // 2015-06-18 15:30:20.100
m.round(5, 'seconds').format( 'YYYY-MM-DD HH:mm:ss.SSS' ); 			// 2015-06-18 15:30:20.000
m.ceil(3, 'minutes').format( 'YYYY-MM-DD HH:mm:ss.SSS' ); 			// 2015-06-18 15:33:00.000
m.floor(16, 'hours').format( 'YYYY-MM-DD HH:mm:ss.SSS' ); 			// 2015-06-18 00:00:00.000
m.ceil(21, 'hours').format( 'YYYY-MM-DD HH:mm:ss.SSS' ); 			// 2015-06-18 21:00:00.000
m.ceil(20, 'hours').format( 'YYYY-MM-DD HH:mm:ss.SSS' ); 			// 2015-06-19 00:00:00.000

Possible values to round to are hours, minutes, seconds, milliseconds

###Alias values

mm --> milliseconds
Milliseconds --> milliseconds
millisecond --> milliseconds
s --> seconds
Seconds --> seconds
second --> seconds
m --> minutes
Minutes --> minutes
minute --> minutes
h --> hours
H --> hours
Hours --> hours
hour --> hours

Installation

Browser

<script src="moment.js"></script>
<script src="moment-round.js"></script>

Node /NPM

WARNING: Not compatible with Webpack. Use SpotOnINC's fork instead.

npm install moment-round --save-dev

And then require it:

var moment = require('moment');
require('moment-round');

Bower

bower install moment-round

Running tests

gulp test

License

moment-round is LICENSED.

About

Plugin for momentjs to round time in dates.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%