Created
June 20, 2016 19:56
-
-
Save vnegrisolo/e61c5e8592c8cbc258240a6564a9d572 to your computer and use it in GitHub Desktop.
Some Date monkey patches, because I don't need to use `moment js` and javascript Date is as useful as airplane horn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date.prototype.advanceDays = function(days) { | |
let d = new Date(this); | |
return new Date(d.setDate(this.getDate() + days)); | |
}; | |
Date.prototype.beginningOfWeek = function() { | |
return this.advanceDays((this.getDay() == 0 ? -6 : 1) - this.getDay()); | |
}; | |
Date.prototype.getWeekName = function() { | |
return ['S', 'M', 'T', 'W', 'T', 'F', 'S'][this.getDay()]; | |
}; | |
Date.prototype.getMonthName = function() { | |
return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][this.getMonth()]; | |
}; | |
Date.prototype.queryFormat = function() { | |
return this.getFullYear() + '-' + (this.getMonth() + 1) + '-' + this.getDate(); | |
}; | |
Date.prototype.simpleFormat = function() { | |
return this.getDate() + ' ' + this.getMonthName(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment