Skip to content

Instantly share code, notes, and snippets.

@Yang03
Created June 13, 2018 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yang03/e8a5e2a31af37c8e8398d0d1bd4cf869 to your computer and use it in GitHub Desktop.
Save Yang03/e8a5e2a31af37c8e8398d0d1bd4cf869 to your computer and use it in GitHub Desktop.
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
},
@Yang03
Copy link
Author

Yang03 commented Jun 13, 2018

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment