Created
February 7, 2019 11:47
-
-
Save tonysaffo/566448fae118314ff08955b8ae310feb to your computer and use it in GitHub Desktop.
Chunk for creating calendar with moment js and react
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
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