Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

iso8601-duration

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iso8601-duration - npm Package Compare versions

Comparing version 1.0.6 to 1.1.1

25

lib/index.js

@@ -42,12 +42,11 @@ 'use strict';

/**
* Convert ISO8601 duration object to seconds
* Convert ISO8601 duration object to an end Date.
*
* @param {Object} duration - The duration object
* @param {Date=} startDate - The starting point for calculating the duration
* @return {Number}
* @param {Date} startDate - The starting Date for calculating the duration
* @return {Date} - The resulting end Date
*/
var toSeconds = exports.toSeconds = function toSeconds(duration, startDate) {
var end = exports.end = function end(duration, startDate) {
// create two equal timestamps, add duration to 'then' and return time difference
var timestamp = startDate ? startDate.getTime() : Date.now();
var now = new Date(timestamp);
var then = new Date(timestamp);

@@ -65,2 +64,17 @@

return then;
};
/**
* Convert ISO8601 duration object to seconds
*
* @param {Object} duration - The duration object
* @param {Date} startDate - The starting point for calculating the duration
* @return {Number}
*/
var toSeconds = exports.toSeconds = function toSeconds(duration, startDate) {
var timestamp = startDate ? startDate.getTime() : Date.now();
var now = new Date(timestamp);
var then = end(duration, startDate);
var seconds = (then.getTime() - now.getTime()) / 1000;

@@ -71,2 +85,3 @@ return seconds;

exports.default = {
end: end,
toSeconds: toSeconds,

@@ -73,0 +88,0 @@ pattern: pattern,

4

package.json
{
"name": "iso8601-duration",
"version": "1.0.6",
"version": "1.1.1",
"description": "Node/Js-module for parsing and making sense of ISO8601-durations",

@@ -11,3 +11,3 @@ "main": "lib/index.js",

"compile": "babel -d lib/ src/",
"prepublish": "npm run compile",
"prepublishOnly": "npm run compile",
"patch-release": "npm test && npm version patch && git push --follow-tags"

@@ -14,0 +14,0 @@ },

@@ -48,3 +48,3 @@ # ISO8601-duration

```js
import {parse, toSeconds, pattern} from 'iso8601-duration';
import {parse, end, toSeconds, pattern} from 'iso8601-duration';

@@ -66,2 +66,5 @@ console.log(parse('P1Y2M4DT20H44M12.67S'));

console.log ( end( parse('P1D') ) );
// outputs => DateObj 2017-10-04T10:14:50.190Z
```

@@ -96,5 +99,6 @@

## License
MIT © Tobias Lundin
MIT @ https://tolu.mit-license.org/

@@ -101,0 +105,0 @@ [1]: https://github.com/sindresorhus/xo "xo on github"

@@ -37,12 +37,11 @@ /**

/**
* Convert ISO8601 duration object to seconds
* Convert ISO8601 duration object to an end Date.
*
* @param {Object} duration - The duration object
* @param {Date=} startDate - The starting point for calculating the duration
* @return {Number}
* @param {Date} startDate - The starting Date for calculating the duration
* @return {Date} - The resulting end Date
*/
export const toSeconds = (duration, startDate) => {
export const end = (duration, startDate) => {
// create two equal timestamps, add duration to 'then' and return time difference
const timestamp = (startDate ? startDate.getTime() : Date.now());
const now = new Date(timestamp);
const then = new Date(timestamp);

@@ -60,2 +59,17 @@

return then;
};
/**
* Convert ISO8601 duration object to seconds
*
* @param {Object} duration - The duration object
* @param {Date} startDate - The starting point for calculating the duration
* @return {Number}
*/
export const toSeconds = (duration, startDate) => {
const timestamp = (startDate ? startDate.getTime() : Date.now());
const now = new Date(timestamp);
const then = end(duration, startDate);
const seconds = (then.getTime() - now.getTime()) / 1000;

@@ -66,2 +80,3 @@ return seconds;

export default {
end,
toSeconds,

@@ -68,0 +83,0 @@ pattern,

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