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