Code Monkey home page Code Monkey logo

moment-round's Introduction

moment-round

โš ๏ธ Not maintained, please visit 1 of the forks.

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.

moment-round's People

Contributors

austencm avatar cjsewell avatar evanshortiss avatar webdevtmas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.