date-diff
Version:
DateDiff is a minimalized Javascript date arithmetic extension.
74 lines (69 loc) • 2.95 kB
JavaScript
function $parcel$defineInteropFlag(a) {
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$defineInteropFlag(module.exports);
$parcel$export(module.exports, "default", () => $5f45703fc88f59e5$export$9099ad97b570f7c);
const $5f45703fc88f59e5$var$divisors = {
days: 86400000,
hours: 3600000,
minutes: 60000,
seconds: 1000
};
const $5f45703fc88f59e5$var$round = (value)=>{
return parseFloat(value.toFixed(1));
};
class $5f45703fc88f59e5$export$9099ad97b570f7c {
constructor(date1, date2){
this.days = ()=>{
return $5f45703fc88f59e5$var$round(this.difference / $5f45703fc88f59e5$var$divisors.days);
};
this.weeks = ()=>{
return $5f45703fc88f59e5$var$round(this.days() / 7);
};
this.hours = ()=>{
return $5f45703fc88f59e5$var$round(this.difference / $5f45703fc88f59e5$var$divisors.hours);
};
this.minutes = ()=>{
return $5f45703fc88f59e5$var$round(this.difference / $5f45703fc88f59e5$var$divisors.minutes);
};
this.seconds = ()=>{
return $5f45703fc88f59e5$var$round(this.difference / $5f45703fc88f59e5$var$divisors.seconds);
};
this.months = ()=>{
let ret = (this.date1.getFullYear() - this.date2.getFullYear()) * 12;
ret += this.date1.getMonth() - this.date2.getMonth();
const endOfMonth = this.endOfMonth(this.date2).getDate();
ret += this.date1.getDate() / endOfMonth - this.date2.getDate() / endOfMonth;
return $5f45703fc88f59e5$var$round(ret);
};
this.years = ()=>{
let ret = this.date1.getFullYear() - this.date2.getFullYear();
ret += (this.dayOfYear(this.date1) - this.dayOfYear(this.date2)) / this.daysInYear(this.date2);
return $5f45703fc88f59e5$var$round(ret);
};
this.endOfMonth = (date)=>{
return new Date(date.getFullYear(), date.getMonth() + 1, 0);
};
this.dayOfYear = (date)=>{
return (date.getTime() - this.beginOfYear(date).getTime()) / $5f45703fc88f59e5$var$divisors.days;
};
this.daysInYear = (date)=>{
return (this.endOfYear(date).getTime() - this.beginOfYear(date).getTime()) / $5f45703fc88f59e5$var$divisors.days;
};
this.beginOfYear = (date)=>{
return new Date(date.getFullYear(), 0, 0);
};
this.endOfYear = (date)=>{
return new Date(date.getFullYear() + 1, 0, 0);
};
this.date1 = date1;
this.date2 = date2;
this.difference = Math.floor(date1.getTime() - date2.getTime());
}
}
Date.diff = (date11, date21)=>new $5f45703fc88f59e5$export$9099ad97b570f7c(date11, date21)
;
//# sourceMappingURL=date-diff.js.map