# moment-precise-range-plugin

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

Latest version **1.3.0** (published 2018-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install moment-precise-range-plugin
pnpm add moment-precise-range-plugin
yarn add moment-precise-range-plugin
bun add moment-precise-range-plugin
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2018-01-07 |
| First published | 2016-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/moment-precise-range-plugin) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 148 |
| Author | Rob Dawson |
| Maintainers | codebox |

## Links

- npm: https://www.npmjs.com/package/moment-precise-range-plugin
- Repository: https://github.com/codebox/moment-precise-range
- Homepage: https://github.com/codebox/moment-precise-range#readme
- Issues: https://github.com/codebox/moment-precise-range/issues
- npm.io page: https://npm.io/package/moment-precise-range-plugin

## Recent versions

- 1.3.0 (latest) — 2018-01-07
- 1.2.4 — 2017-08-03
- 1.2.3 — 2017-05-29
- 1.2.2 — 2017-05-29
- 1.2.1 — 2017-01-21
- 1.2.0 — 2016-05-22
- 1.1.1 — 2016-03-31
- 1.1.0 — 2016-03-31
- 1.0.1 — 2016-03-29
- 1.0.0 — 2016-03-29

## README

# moment-precise-range

This is a plugin for the <a href="http://momentjs.com/">moment.js</a> 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 <a href="https://tonicdev.com/npm/moment-precise-range-plugin">tonicdev</a>

---
_Source: https://npm.io/package/moment-precise-range-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
