frontend/src/helpers/time/calculateNearestHours.ts
konrad c45911fd36 Fix date parsing parsing words with weekdays in them (#607)
Co-authored-by: kolaente <k@knt.li>
Reviewed-on: vikunja/frontend#607
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
2021-07-25 10:45:17 +00:00

24 lines
441 B
TypeScript

export function calculateNearestHours(currentDate: Date = new Date()): number {
if (currentDate.getHours() <= 9 || currentDate.getHours() > 21) {
return 9
}
if (currentDate.getHours() <= 12) {
return 12
}
if (currentDate.getHours() <= 15) {
return 15
}
if (currentDate.getHours() <= 18) {
return 18
}
if (currentDate.getHours() <= 21) {
return 21
}
// Same case as in the first if, will never be called
return 9
}