Skip to content

Instantly share code, notes, and snippets.

@tonysaffo
Created February 7, 2019 11:47
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 tonysaffo/566448fae118314ff08955b8ae310feb to your computer and use it in GitHub Desktop.
Save tonysaffo/566448fae118314ff08955b8ae310feb to your computer and use it in GitHub Desktop.
Chunk for creating calendar with moment js and react
updateDates = () => {
const date = this.state.currentDate.startOf('month')
const delta = Math.abs(1-date.day())
let daysInMonth = date.daysInMonth() + delta
date.subtract(delta+1, 'd')
const arrayOfDays = []
while(daysInMonth > 0){
let dateNew = Moment(date.add(1, 'd'))
arrayOfDays.push(dateNew)
daysInMonth-=1
}
this.setState({ calendar: arrayOfDays })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment