Skip to content

Commit

Permalink
use standard formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmueller committed Oct 14, 2016
1 parent a495343 commit 5627ac9
Show file tree
Hide file tree
Showing 7 changed files with 793 additions and 805 deletions.
194 changes: 97 additions & 97 deletions lib/date.js
Expand Up @@ -8,19 +8,19 @@ var debug = require('debug')('date:date')
* Time constants
*/

var _second = 1000;
var _minute = 60 * _second;
var _hour = 60 * _minute;
var _day = 24 * _hour;
var _week = 7 * _day;
var _year = 56 * _week;
var _daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var _second = 1000
var _minute = 60 * _second
var _hour = 60 * _minute
var _day = 24 * _hour
var _week = 7 * _day
var _year = 56 * _week
var _daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

/**
* Expose `date`
*/

module.exports = date;
module.exports = date

/**
* Initialize `date`
Expand All @@ -30,18 +30,18 @@ module.exports = date;
* @api publics
*/

function date(offset) {
if(!(this instanceof date)) return new date(offset);
this._changed = {};
this.date = new Date(offset);
};
function date (offset) {
if (!(this instanceof date)) return new date(offset)
this._changed = {}
this.date = new Date(offset)
}

/**
* Clone the current date
*/

date.prototype.clone = function() {
return new Date(this.date);
date.prototype.clone = function () {
return new Date(this.date)
}

/**
Expand All @@ -51,10 +51,10 @@ date.prototype.clone = function() {
* @return {Boolean}
*/

date.prototype.changed = function(str) {
if (this._changed[str] === undefined) return false;
return this._changed[str];
};
date.prototype.changed = function (str) {
if (this._changed[str] === undefined) return false
return this._changed[str]
}

/**
* add or subtract seconds
Expand All @@ -63,11 +63,11 @@ date.prototype.changed = function(str) {
* @return {date}
*/

date.prototype.second = function(n) {
var seconds = +n * _second;
this.update(seconds);
this._changed['seconds'] = true;
return this;
date.prototype.second = function (n) {
var seconds = +n * _second
this.update(seconds)
this._changed['seconds'] = true
return this
}

/**
Expand All @@ -77,11 +77,11 @@ date.prototype.second = function(n) {
* @return {date}
*/

date.prototype.minute = function(n) {
var minutes = +n * _minute;
this.update(minutes);
this._changed['minutes'] = true;
return this;
date.prototype.minute = function (n) {
var minutes = +n * _minute
this.update(minutes)
this._changed['minutes'] = true
return this
}

/**
Expand All @@ -91,11 +91,11 @@ date.prototype.minute = function(n) {
* @return {date}
*/

date.prototype.hour = function(n) {
var hours = +n * _hour;
this.update(hours);
this._changed['hours'] = true;
return this;
date.prototype.hour = function (n) {
var hours = +n * _hour
this.update(hours)
this._changed['hours'] = true
return this
}

/**
Expand All @@ -105,11 +105,11 @@ date.prototype.hour = function(n) {
* @return {date}
*/

date.prototype.day = function(n) {
var days = +n * _day;
this.update(days);
this._changed['days'] = true;
return this;
date.prototype.day = function (n) {
var days = +n * _day
this.update(days)
this._changed['days'] = true
return this
}

/**
Expand All @@ -119,11 +119,11 @@ date.prototype.day = function(n) {
* @return {date}
*/

date.prototype.week = function(n) {
var weeks = +n * _week;
this.update(weeks);
this._changed['weeks'] = true;
return this;
date.prototype.week = function (n) {
var weeks = +n * _week
this.update(weeks)
this._changed['weeks'] = true
return this
}

/**
Expand All @@ -133,28 +133,28 @@ date.prototype.week = function(n) {
* @return {Date}
*/

date.prototype.month = function(n) {
var d = this.date;
var day = d.getDate();
d.setDate(1);
var month = +n + d.getMonth();
d.setMonth(month);
date.prototype.month = function (n) {
var d = this.date
var day = d.getDate()
d.setDate(1)
var month = +n + d.getMonth()
d.setMonth(month)

// Handle dates with less days
var dim = this.daysInMonth(month)
d.setDate(Math.min(dim, day));
return this;
};
d.setDate(Math.min(dim, day))
return this
}

/**
* get the days in the month
*/

date.prototype.daysInMonth = function(m) {
var dim = _daysInMonth[m];
var leap = leapyear(this.date.getFullYear());
return (1 == m && leap) ? 29 : 28;
};
date.prototype.daysInMonth = function (m) {
var dim = _daysInMonth[m]
var leap = leapyear(this.date.getFullYear())
return (1 == m && leap) ? 29 : 28
}

/**
* add or subtract years
Expand All @@ -163,12 +163,12 @@ date.prototype.daysInMonth = function(m) {
* @return {date}
*/

date.prototype.year = function(n) {
var yr = this.date.getFullYear();
yr += +n;
this.date.setFullYear(yr);
this._changed['years'] = true;
return this;
date.prototype.year = function (n) {
var yr = this.date.getFullYear()
yr += +n
this.date.setFullYear(yr)
this._changed['years'] = true
return this
}

/**
Expand All @@ -180,43 +180,43 @@ date.prototype.year = function(n) {
* @return {date}
*/

date.prototype.time = function(h, m, s, meridiem) {
date.prototype.time = function (h, m, s, meridiem) {
if (h === false) {
h = this.date.getHours();
h = this.date.getHours()
} else {
h = +h || 0;
this._changed['hours'] = h;
h = +h || 0
this._changed['hours'] = h
}

if (m === false) {
m = this.date.getMinutes();
m = this.date.getMinutes()
} else {
m = +m || 0;
this._changed['minutes'] = m;
m = +m || 0
this._changed['minutes'] = m
}

if (s === false) {
s = this.date.getSeconds();
s = this.date.getSeconds()
} else {
s = +s || 0;
this._changed['seconds'] = s;
s = +s || 0
this._changed['seconds'] = s
}

this.date.setHours(h, m, s);
return this;
};
this.date.setHours(h, m, s)
return this
}

/**
* Dynamically create day functions (sunday(n), monday(n), etc.)
*/

var days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
days.forEach(function(day, i) {
date.prototype[days[i]] = function(n) {
this._changed['days'] = true;
this.updateDay(i, n);
};
});
var days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
days.forEach(function (day, i) {
date.prototype[days[i]] = function (n) {
this._changed['days'] = true
this.updateDay(i, n)
}
})

/**
* go to day of week
Expand All @@ -226,13 +226,13 @@ days.forEach(function(day, i) {
* @return {date}
*/

date.prototype.updateDay = function(d, n) {
n = +(n || 1);
var diff = (d - this.date.getDay() + 7) % 7;
if (n > 0) --n;
diff += (7 * n);
this.update(diff * _day);
return this;
date.prototype.updateDay = function (d, n) {
n = +(n || 1)
var diff = (d - this.date.getDay() + 7) % 7
if (n > 0) --n
diff += (7 * n)
this.update(diff * _day)
return this
}

/**
Expand All @@ -243,10 +243,10 @@ date.prototype.updateDay = function(d, n) {
* @api private
*/

date.prototype.update = function(ms) {
this.date = new Date(this.date.getTime() + ms);
return this;
};
date.prototype.update = function (ms) {
this.date = new Date(this.date.getTime() + ms)
return this
}

/**
* leap year
Expand All @@ -255,6 +255,6 @@ date.prototype.update = function(ms) {
* @return {Boolean}
*/

function leapyear(yr) {
return (yr % 4 === 0 && yr % 100 !== 0) || yr % 400 === 0;
function leapyear (yr) {
return (yr % 4 === 0 && yr % 100 !== 0) || yr % 400 === 0
}

0 comments on commit 5627ac9

Please sign in to comment.