date-diff
Version:
DateDiff is a minimalized Javascript date arithmetic extension.
65 lines (62 loc) • 2.64 kB
JavaScript
const $8f392239b348c51c$var$divisors = {
days: 86400000,
hours: 3600000,
minutes: 60000,
seconds: 1000
};
const $8f392239b348c51c$var$round = (value)=>{
return parseFloat(value.toFixed(1));
};
class $8f392239b348c51c$export$9099ad97b570f7c {
constructor(date1, date2){
this.days = ()=>{
return $8f392239b348c51c$var$round(this.difference / $8f392239b348c51c$var$divisors.days);
};
this.weeks = ()=>{
return $8f392239b348c51c$var$round(this.days() / 7);
};
this.hours = ()=>{
return $8f392239b348c51c$var$round(this.difference / $8f392239b348c51c$var$divisors.hours);
};
this.minutes = ()=>{
return $8f392239b348c51c$var$round(this.difference / $8f392239b348c51c$var$divisors.minutes);
};
this.seconds = ()=>{
return $8f392239b348c51c$var$round(this.difference / $8f392239b348c51c$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 $8f392239b348c51c$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 $8f392239b348c51c$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()) / $8f392239b348c51c$var$divisors.days;
};
this.daysInYear = (date)=>{
return (this.endOfYear(date).getTime() - this.beginOfYear(date).getTime()) / $8f392239b348c51c$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 $8f392239b348c51c$export$9099ad97b570f7c(date11, date21)
;
export {$8f392239b348c51c$export$9099ad97b570f7c as default};
//# sourceMappingURL=date-diff.module.js.map