duration-js

WebJar for duration-js

License

License

MIT
Categories

Categories

JavaScript Languages
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

duration-js
Last Version

Last Version

4.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

duration-js
WebJar for duration-js
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/icholy/Duration.js

Download duration-js

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/duration-js/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>duration-js</artifactId>
    <version>4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/duration-js/
implementation 'org.webjars.npm:duration-js:4.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/duration-js/
implementation ("org.webjars.npm:duration-js:4.0.0")
'org.webjars.npm:duration-js:jar:4.0.0'
<dependency org="org.webjars.npm" name="duration-js" rev="4.0.0">
  <artifact name="duration-js" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='duration-js', version='4.0.0')
)
libraryDependencies += "org.webjars.npm" % "duration-js" % "4.0.0"
[org.webjars.npm/duration-js "4.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Duration Build Status

This is a library for dealing with durations. It works well with javascript's Date objects.

$ npm install @icholy/duration
import Duration from "@icholy/duration";

Parse

  • ms - millisecond
  • s - second
  • m - minute
  • h - hour
  • d - day
  • w - week
var d = new Duration("6w5d4h3m2s1ms");

console.log(
    d.milliseconds(), "\n", // => 4075382001
    d.seconds(),      "\n", // => 4075382
    d.minutes(),      "\n", // => 67923
    d.hours(),        "\n", // => 1132
    d.days(),         "\n", // => 47
    d.weeks(),        "\n"  // => 6
);

Format

console.log(
  "str:",  Duration.hour.toString(),
  "ms:",   Duration.hour.valueOf()
); // => "str: 1h ms: 3600000"

Basic Operations

// Addition
var d1 = new Duration("6d"),
    d2 = new Duration(d1 + Duration.day);
console.log(d2.toString()) // => "168h"

// Multiplication
var d3 = new Duration("5m"),
    d4 = new Duration(d3 * 12);
console.log(d4.toString()) // => "1h"

// etc ...

Dates

// Adding duration to date
var d     = Duration.parse("5h"),
    now   = new Date(),
    later = new Date(now + d);
console.log(later.toString());

// Duration between two dates
var bday = new Date("March 3, 1991"),
    now  = new Date(),
    age  = new Duration(now - bday);
console.log(age.toString());

setTimeout / setInterval

setTimeout(function () {
    // runs 5 minutes later
}, new Duration("5m"));

setInterval(function () {
    // runs every 10 seconds 
}, 10 * Duration.second);

Versions

Version
4.0.0