This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/hourToDaytime.ts
Dominik Pschenitschni 5afafb7c82
All checks were successful
continuous-integration/drone/pr Build is passing
fix: move hourToDaytime to separate file in order to pass tests
2022-10-17 12:35:47 +02:00

15 lines
402 B
TypeScript

import type { Daytime } from '@/composables/useDaytimeSalutation'
export function hourToDaytime(now: Date): Daytime {
const hours = now.getHours()
const daytimeMap = {
night: hours < 5 || hours > 23,
morning: hours < 11,
day: hours < 18,
evening: hours < 23,
} as Record<Daytime, boolean>
return (Object.keys(daytimeMap) as Daytime[]).find((daytime) => daytimeMap[daytime]) || 'night'
}