vikunja-frontend/src/composables/useDateTimeSalutation.ts

31 lines
612 B
TypeScript
Raw Normal View History

import {computed} from 'vue'
import {useNow} from '@vueuse/core'
2021-12-30 17:14:43 +01:00
const TRANSLATION_KEY_PREFIX = 'home.welcome'
export function hourToSalutation(now: Date) {
const hours = now.getHours()
if (hours < 5) {
2021-12-30 17:14:43 +01:00
return `${TRANSLATION_KEY_PREFIX}Night`
}
if (hours < 11) {
2021-12-30 17:14:43 +01:00
return `${TRANSLATION_KEY_PREFIX}Morning`
}
if (hours < 18) {
2021-12-30 17:14:43 +01:00
return `${TRANSLATION_KEY_PREFIX}Day`
}
if (hours < 23) {
2021-12-30 17:14:43 +01:00
return `${TRANSLATION_KEY_PREFIX}Evening`
}
2021-12-30 17:14:43 +01:00
return `${TRANSLATION_KEY_PREFIX}Night`
}
export function useDateTimeSalutation() {
const now = useNow()
return computed(() => hourToSalutation(now.value))
}