Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.89 KB

README.md

File metadata and controls

45 lines (32 loc) · 1.89 KB

DateDuration

The DateDuration class represents a duration of time specified in milliseconds. It provides methods to calculate and retrieve information about the duration.

Deno Version Npmjs.org Version GitHub Workflow Status Test Coverage NPM Downloads

Install (npm)

pnpm add @jmondi/date-duration

Deno

import { DateDuration } from "https://deno.land/x/date_duration";

Usage

The class is based on the ms package.

const duration = new DateDuration("2d");

Access the properties and methods of the DateDuration instance:

console.log(duration.endDate);          // Get the end date as a JavaScript Date object
console.log(duration.endTimeMs);        // Get the end time in milliseconds
console.log(duration.endTimeSeconds);   // Get the end time in seconds (rounded up)
console.log(duration.seconds);          // Get the duration in seconds (rounded up)

You can also use the static method getDateEnd to get the end date directly without creating an instance:

const endDate = DateDuration.getDateEnd("1w");
console.log(endDate);  // Get the end date as a JavaScript Date object