@everwhen/temporal
Version:
_description_
43 lines (42 loc) • 1.25 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);
}
const args = { unit };
if (opts?.relativeTo) {
args.relativeTo = opts?.relativeTo;
}
return duration.total(args);
}
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());
}
}