Skip to content

Instantly share code, notes, and snippets.

@Killavus
Created July 7, 2016 13:44
Show Gist options
  • Save Killavus/cc9016e9ba2fbf9c080e99990317435b to your computer and use it in GitHub Desktop.
Save Killavus/cc9016e9ba2fbf9c080e99990317435b to your computer and use it in GitHub Desktop.
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