},
options(): ReminderOption[] {
- const computeOption = (option: ReminderOption) => {
+ const computeOption = (option: ReminderOption): null | ReminderOption => {
const dateTime = getDateTime(option.dateTimePreset)
+ if (!dateTime) {
+ return null
+ }
return {
...option,
ariaLabel: `${option.ariaLabel} – ${getVerboseDateString(dateTime)}`,
}
}
- return [
+ const options = [
laterToday,
tomorrow,
thisWeekend,
nextWeek,
- ].map(computeOption)
+ ]
+ return options
+ .map(computeOption)
+ .filter(Boolean) as ReminderOption[]
},
},
NextWeek,
}
-export const getDateTime = (dateTime: DateTimePreset): Date => {
- const matchPreset: Record<DateTimePreset, () => Date> = {
+export const getDateTime = (dateTime: DateTimePreset): null | Date => {
+ const matchPreset: Record<DateTimePreset, () => null | Date> = {
[DateTimePreset.LaterToday]: () => {
- const hour = moment().get('hour')
- const later = moment()
+ const now = moment()
+ const evening = moment()
.startOf('day')
- .add(hour + 3, 'hour')
- return later.toDate()
+ .add(18, 'hour')
+ if (now.isSameOrAfter(evening)) {
+ return null
+ }
+ return evening.toDate()
},
[DateTimePreset.Tomorrow]: () => {
.add(1, 'day')
.startOf('day')
.add(8, 'hour')
- .toDate()
- return day
+ return day.toDate()
},
[DateTimePreset.ThisWeekend]: () => {
.startOf('isoWeek')
.add(1, 'week')
.add(8, 'hour')
- .toDate()
- return day
+ return day.toDate()
},
}