chrono-convert
Version:
Effortlessly manipulate and convert time units with Chrono: a fluent, chainable interface for clear and precise time calculations. Perfect for adding time-based logic to your applications with just a few lines of code.
7 lines (5 loc) • 1.72 kB
JavaScript
'use strict';
var s=class e{value;constructor(t){this.value=t;}static milliseconds(t){return new e(t/1e3)}static ms(t){return e.milliseconds(t)}static seconds(t){return new e(t)}static minutes(t){return new e(t*60)}static hours(t){return new e(t*3600)}static days(t){return new e(t*86400)}static weeks(t){return new e(t*604800)}static months(t){return new e(t*2628e3)}static quarters(t){return new e(t*2628e3*3)}static years(t){return new e(t*31536e3)}static from(t,r){return new e(e.getValueByUnit(t,r))}fixValue(t){return Math.round(t*1e4)/1e4}static getValueByUnit(t,r){return {milliseconds:t/1e3,ms:t/1e3,seconds:t,minutes:t*60,hours:t*3600,days:t*86400,weeks:t*604800,months:t*2628e3,quarters:t*7884e3,years:t*31536e3}[r]}add(t,r){return new e(this.value+e.getValueByUnit(t,r))}subtract(t,r){return new e(this.value-e.getValueByUnit(t,r))}to(t){return {milliseconds:this.toMilliseconds(),ms:this.toMilliseconds(),seconds:this.toSeconds(),minutes:this.toMinutes(),hours:this.toHours(),days:this.toDays(),weeks:this.toWeeks(),months:this.toMonths(),quarters:this.toQuarters(),years:this.toYears()}[t]}toMilliseconds(){return this.fixValue(this.value*1e3)}toMs(){return this.toMilliseconds()}toSeconds(){return this.fixValue(this.value)}toMinutes(){return this.fixValue(this.value/60)}toHours(){return this.fixValue(this.value/3600)}toDays(){return this.fixValue(this.value/86400)}toWeeks(){return this.fixValue(this.value/604800)}toMonths(){return this.fixValue(this.value/2628e3)}toQuarters(){return this.fixValue(this.value/7884e3)}toYears(){return this.fixValue(this.value/31536e3)}toString(){return `${this.value}`}},l=s;
module.exports = l;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.cjs.map