@everwhen/temporal
Version:
39 lines • 1.2 kB
JavaScript
import { Temporal } from 'temporal-polyfill';
export class Duration extends Temporal.Duration {
static from(...args) {
const d = Temporal.Duration.from(...args);
return new Duration(d.years, d.months, d.weeks, d.days, d.hours, d.minutes, d.seconds, d.milliseconds, d.microseconds, d.nanoseconds);
}
compare(other, options) {
return Temporal.Duration.compare(this, other, options);
}
get isNegated() {
return this.sign === -1;
}
sum(unit, opts) {
let duration = Duration.from(this);
if (opts?.roundOf) {
duration = this.round(opts.roundOf);
}
return duration.total({ unit, relativeTo: opts?.relativeTo });
}
round(roundTo) {
return Duration.from(super.round(roundTo));
}
add(other) {
return Duration.from(super.add(other));
}
subtract(other) {
return Duration.from(super.subtract(other));
}
negated() {
return Duration.from(super.negated());
}
with(durationLike) {
return Duration.from(super.with(durationLike));
}
abs() {
return Duration.from(super.abs());
}
}
//# sourceMappingURL=duration.js.map