forked from melvinsembrano/date-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate-diff.min.js
More file actions
7 lines (6 loc) · 1.72 KB
/
Copy pathdate-diff.min.js
File metadata and controls
7 lines (6 loc) · 1.72 KB
1
2
3
4
5
6
7
/*!
date-diff 0.2.1
Description: DateDiff is a minimalized Javascript date arithmetic extension.
Author: Melvin Sembrano <melvinsembrano@gmail.com> (https://github.com/melvinsembrano/date-diff)
*/
(function(){var n,e;e={days:864e5,hours:36e5,minutes:6e4,seconds:1e3},(n=function(t,e){this.date1=t,this.date2=e,this.difference=Math.floor(t-e)}).prototype.weeks=function(){return this._roundIt(this.days()/7)},n.prototype.days=function(){return this._roundIt(this.difference/e.days)},n.prototype.hours=function(){return this._roundIt(this.difference/e.hours)},n.prototype.minutes=function(){return this._roundIt(this.difference/e.minutes)},n.prototype.seconds=function(){return this._roundIt(this.difference/e.seconds)},n.prototype.months=function(){var t,e;return e=12*(this.date1.getFullYear()-this.date2.getFullYear()),e+=this.date1.getMonth()-this.date2.getMonth(),t=this.endOfMonth(this.date2).getDate(),e+=this.date1.getDate()/t-this.date2.getDate()/t,this._roundIt(e)},n.prototype.years=function(){var t;return t=this.date1.getFullYear()-this.date2.getFullYear(),t+=(this.dayOfYear(this.date1)-this.dayOfYear(this.date2))/this.daysInYear(this.date2),this._roundIt(t)},n.prototype.endOfMonth=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0)},n.prototype.endOfYear=function(t){return new Date(t.getFullYear()+1,0,0)},n.prototype.beginOfYear=function(t){return new Date(t.getFullYear(),0,0)},n.prototype.dayOfYear=function(t){return(t-this.beginOfYear(t))/e.days},n.prototype.daysInYear=function(t){return(this.endOfYear(t)-this.beginOfYear(t))/e.days},n.prototype._roundIt=function(t){return parseFloat(t.toFixed(1))},Date.diff=function(t,e){return new n(t,e)},this.DateDiff=n,"undefined"!=typeof module&&(module.exports=n)}).call(this);