Duration
Everything in this package is based around the Duration class, where you can create a duration and add/subtract time or get the end date in different formats.
Type: Object
Constructor
new Duration('1w 2d');
//OR
new Duration({ weeks: 1, days: 2 });
Properties
.duration
The main duration object.
Type: Temporal.Instant
Methods
.add(duration, options?)
Adds to the current duration. Can either be a string or TemporalDuration
Returns: Duration
.sub(duration, options?)
Subtracts from the current duration. Can either be a string or TemporalDuration
Returns: Duration
.endDate(options?)
Returns the end date as a Date object.
ParameterTypeOptional
Returns: Date
.toDiscordTimestamp(type, options?)
Returns the end date as a Discord Timestamp string.
Returns: String
.toString()
Shows the current duration as a string
Example:
import { Duration } from '@fleco/duration';
const dur = new Duration({ milliseconds: 12389348 });
console.log(dur.toString()); //Output: '3 hours 26 minutes 29 seconds'
Returns: String