Created
June 13, 2018 05:58
-
-
Save Yang03/e8a5e2a31af37c8e8398d0d1bd4cf869 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function daysInMonth (year, month) { | |
return /8|3|5|10/.test(month) ? 30 : month === 1 ? (!(year % 4) && year % 100) || !(year % 400) ? 29 : 28 : 31 | |
} | |
function formatDate (date, format, translation) { | |
translation = (!translation) ? en : translation | |
let year = date.getFullYear() | |
let month = date.getMonth() + 1 | |
let day = date.getDate() | |
let str = format | |
.replace(/dd/, ('0' + day).slice(-2)) | |
.replace(/d/, day) | |
.replace(/yyyy/, year) | |
.replace(/yy/, String(year).slice(2)) | |
.replace(/MMMM/, this.getMonthName(date.getMonth(), translation.months)) | |
.replace(/MMM/, this.getMonthNameAbbr(date.getMonth(), translation.monthsAbbr)) | |
.replace(/MM/, ('0' + month).slice(-2)) | |
.replace(/M(?!a|ä|e)/, month) | |
.replace(/su/, this.getNthSuffix(date.getDate())) | |
.replace(/D(?!e|é|i)/, this.getDayNameAbbr(date, translation.days)) | |
return str | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function createDateArray (start, end) {
let dates = []
while (start <= end) {
dates.push(new Date(start))
start = new Date(start).setDate(new Date(start).getDate() + 1)
}
return dates
}