
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@icholy/duration
Advanced tools
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";
ms
- milliseconds
- secondm
- minuteh
- hourd
- dayw
- weekvar 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
);
console.log(
"str:", Duration.hour.toString(),
"ms:", Duration.hour.valueOf()
); // => "str: 1h ms: 3600000"
// 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 ...
// 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(function () {
// runs 5 minutes later
}, new Duration("5m"));
setInterval(function () {
// runs every 10 seconds
}, 10 * Duration.second);
FAQs
class for working with time durations
The npm package @icholy/duration receives a total of 631 weekly downloads. As such, @icholy/duration popularity was classified as not popular.
We found that @icholy/duration demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.