Socket
Socket
Sign inDemoInstall

dayjs-precise-range

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dayjs-precise-range

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


Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

dayjs-precise-range

This is a plugin for the dayjs.js and inspired from moment-date-range-plugin 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 dayjs = require('dayjs');
var relativeTime = require('dayjs/plugin/relativeTime')
dayjs.extend(relativeTime)
var m1 = dayjs('2014-01-01 12:00:00');
var m2 = dayjs('2014-02-03 15:04:05');
var diff = m1().from(m2,true) // 'a month'

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

var dayjs = require('dayjs');
var preciseDiff = require('dayjs-precise-range');
//or
//var preciseDiff = require('dayjs/plugin/preciseDiff')
dayjs.extend(preciseDiff);
var m1 = dayjs('2014-01-01 12:00:00');
var m2 = dayjs('2014-02-03 15:04:05');
var diff = dayjs.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/days.js"></script>
<script src="/scripts/days-precise-range.js"></script>

Node.js

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

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

Keywords

FAQs

Package last updated on 18 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc