All Projects → codebox → Moment Precise Range

codebox / Moment Precise Range

Licence: mit
A moment.js plugin to display human-readable date/time ranges

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Moment Precise Range

react-native-daterange-picker
A React Native component for picking date ranges or single dates.
Stars: ✭ 86 (-35.82%)
Mutual labels:  range, moment
Vuetify Daterange Picker
The missing date range picker for Vuetify JS you have been looking for.
Stars: ✭ 192 (+43.28%)
Mutual labels:  moment, range
Ngx Moment
moment.js pipes for Angular
Stars: ✭ 1,127 (+741.04%)
Mutual labels:  moment
Range
A JavaScript implementation of the Python's range() function.
Stars: ✭ 110 (-17.91%)
Mutual labels:  range
Vue Typescript Music
🔥 基于 vue 全家桶 音乐项目(Music project) vue+typescript 实现 高仿 网易云音乐 移动端WebApp
Stars: ✭ 94 (-29.85%)
Mutual labels:  moment
Rc Datetime Picker
React component for datetime picker by Moment.js
Stars: ✭ 85 (-36.57%)
Mutual labels:  moment
Moment Timer
Timer plugin for Moment.js that allows creation of setInterval and setTimeout-like timers.
Stars: ✭ 98 (-26.87%)
Mutual labels:  moment
Range Slider
The simplest JavaScript custom range slider ever!
Stars: ✭ 41 (-69.4%)
Mutual labels:  range
Moment Range
Fancy date ranges for Moment.js
Stars: ✭ 1,639 (+1123.13%)
Mutual labels:  moment
Monster
The Art of Template MetaProgramming (TMP) in Modern C++♦️
Stars: ✭ 90 (-32.84%)
Mutual labels:  range
Pg Calendar
📆 beautiful and eidetic date picker
Stars: ✭ 109 (-18.66%)
Mutual labels:  moment
Moment Business
Utilities for work days in Moment. (Western workweeks only.)
Stars: ✭ 91 (-32.09%)
Mutual labels:  moment
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: ✭ 88 (-34.33%)
Mutual labels:  moment
Spans
Spans is a pure Python implementation of PostgreSQL's range types.
Stars: ✭ 106 (-20.9%)
Mutual labels:  range
Range Parser
Range header field parser
Stars: ✭ 78 (-41.79%)
Mutual labels:  range
Polypoint
Indoor localization based on the DecaWave DW1000.
Stars: ✭ 119 (-11.19%)
Mutual labels:  range
Persianrangedatepicker
Persian range date picker for android.
Stars: ✭ 48 (-64.18%)
Mutual labels:  range
Functionalplus
Functional Programming Library for C++. Write concise and readable C++ code.
Stars: ✭ 1,286 (+859.7%)
Mutual labels:  range
To Regex Range
Pass two numbers, get a regex-compatible source string for matching ranges. Fast compiler, optimized regex, and validated against more than 2.78 million test assertions. Useful for creating regular expressions to validate numbers, ranges, years, etc.
Stars: ✭ 97 (-27.61%)
Mutual labels:  range
A Joke
🤡 A-Joke { 一个笑话,目的就是能够在工作之余博君一笑,尽得人生笑开颜 }
Stars: ✭ 135 (+0.75%)
Mutual labels:  moment

moment-precise-range

This is a plugin for the moment.js JavaScript library, to display date/time ranges precisely, in a human-readable format.

Moment already contains some support for formatting date/time ranges, however it performs a lot of 'rounding' on the result and yields only an approximate description.

In the example below the difference between the 2 dates is 1 month, 2 days, 3 hours, 4 minutes and 5 seconds exactly, however this is simplified to just 'a month' by the library.

var m1 = moment('2014-01-01 12:00:00','YYYY-MM-DD HH:mm:ss');
var m2 = moment('2014-02-03 15:04:05','YYYY-MM-DD HH:mm:ss');
var diff = moment.duration(m1.diff(m2)).humanize(); // 'a month'

Using the plugin, we can display the exact difference using the same 2 dates:

var m1 = moment('2014-01-01 12:00:00','YYYY-MM-DD HH:mm:ss');
var m2 = moment('2014-02-03 15:04:05','YYYY-MM-DD HH:mm:ss');
var diff = moment.preciseDiff(m1, m2); // '1 month 2 days 3 hours 4 minutes 5 seconds'

To obtain the numeric values rather than a string, pass the value true as the third argument to the method:

var diff = moment.preciseDiff(m1, m2, true); // {years : 0, months : 1, days : 2, hours : 3, minutes : 4, seconds : 5}

Usage

HTML/Browser

To use the plugin in a web page, add a <script> tag referencing the moment-precise-range.js file, ensuring that the tag appears after the tag used to include the moment.js library:

<script src="/scripts/moment.js"></script>
<script src="/scripts/moment-precise-range.js"></script>

Node.js

To use the plugin within a node.js application, add the following require statement into your code:

require('moment-precise-range-plugin');

You can try out the Node package online at tonicdev

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].