Created
July 7, 2016 13:44
-
-
Save Killavus/cc9016e9ba2fbf9c080e99990317435b 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
dayOptions() { | |
const { date } = this.props; | |
const month = date.getMonth(); | |
const year = date.getFullYear(); | |
const possibleDays = makeRange(1, 31); | |
const actualDays = possibleDays.filter(day => { | |
// We take an advantage of the fact that if you | |
// specify the 'invalid' date like 31st of February | |
// it'll automatically switch to the next month. | |
// So new Date(2016, 1, 90) === Apr 30th 2016 | |
const possibleDate = new Date(year, month, day); | |
return possibleDate.getMonth() === month; | |
}); | |
const actualDayOfWeeks = actualDays.map(day => { | |
const date = new Date(year, month, day); | |
return date.getDay(); | |
}); | |
return zip(actualDays, actualDayOfWeeks).map( | |
([day, dayOfWeek]) => ( | |
<option value={day}> | |
{day} - {dayName(dayOfWeek)} | |
</option>); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment