fix: move hourToDaytime to separate file in order to pass tests
This commit is contained in:
parent
9de20b4c54
commit
5afafb7c82
@ -3,23 +3,11 @@ import {useI18n} from 'vue-i18n'
|
||||
import {useNow} from '@vueuse/core'
|
||||
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
import {hourToDaytime} from '@/helpers/hourToDaytime'
|
||||
|
||||
type Daytime = 'night' | 'morning' | 'day' | 'evening'
|
||||
export type Daytime = 'night' | 'morning' | 'day' | 'evening'
|
||||
|
||||
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'
|
||||
}
|
||||
|
||||
export function useDateTimeSalutation() {
|
||||
export function useDaytimeSalutation() {
|
||||
const {t} = useI18n({useScope: 'global'})
|
||||
const now = useNow()
|
||||
const authStore = useAuthStore()
|
@ -1,5 +1,5 @@
|
||||
import {describe, it, expect} from 'vitest'
|
||||
import {hourToDaytime} from './useDateTimeSalutation'
|
||||
import {hourToDaytime} from "./hourToDaytime"
|
||||
|
||||
function dateWithHour(hours: number): Date {
|
||||
const newDate = new Date()
|
14
src/helpers/hourToDaytime.ts
Normal file
14
src/helpers/hourToDaytime.ts
Normal file
@ -0,0 +1,14 @@
|
||||
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'
|
||||
}
|
@ -68,7 +68,7 @@ import AddTask from '@/components/tasks/add-task.vue'
|
||||
import {getHistory} from '@/modules/listHistory'
|
||||
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
|
||||
import {formatDateShort, formatDateSince} from '@/helpers/time/formatDate'
|
||||
import {useDateTimeSalutation} from '@/composables/useDateTimeSalutation'
|
||||
import {useDaytimeSalutation} from '@/composables/useDaytimeSalutation'
|
||||
|
||||
import {useBaseStore} from '@/stores/base'
|
||||
import {useListStore} from '@/stores/lists'
|
||||
@ -77,7 +77,7 @@ import {useNamespaceStore} from '@/stores/namespaces'
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
|
||||
const salutation = useDateTimeSalutation()
|
||||
const salutation = useDaytimeSalutation()
|
||||
|
||||
const baseStore = useBaseStore()
|
||||
const authStore = useAuthStore()
|
||||
|
Loading…
x
Reference in New Issue
Block a user