Skip to content

Commit 2c0cac8

Browse files
committed
fix: countdown time
1 parent 366ce92 commit 2c0cac8

6 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/components/home/CountdownHeader.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { conId, conName, conTimeZone } from '@/configuration'
1010
import { useCache } from '@/context/data/Cache'
1111
import { EventDayRecord } from '@/context/data/types.api'
1212
import { useNow } from '@/hooks/time/useNow'
13+
import { dateFnsLocales } from '@/i18n'
1314
import { parseDefaultISO } from '@/util/parseDefaultISO'
1415

1516
import { Image } from '../generic/atoms/Image'
@@ -36,7 +37,7 @@ const isSameDayInTimezone = (date1: Date, date2: string, timezone: string) => {
3637
/**
3738
* Calculates the countdown title based on current time and event days.
3839
*/
39-
const useCountdownTitle = (t: TFunction, now: Date) => {
40+
const useCountdownTitle = (t: TFunction, now: Date, currentLanguage: string) => {
4041
const { eventDays } = useCache()
4142
const firstDay = eventDays[0]
4243
const lastDay = eventDays[eventDays.length - 1]
@@ -49,7 +50,8 @@ const useCountdownTitle = (t: TFunction, now: Date) => {
4950
if (firstDay) {
5051
const firstDate = new Date(firstDay.Date)
5152
if (now < firstDate) {
52-
const diff = formatDistance(firstDate, now)
53+
const locale = dateFnsLocales[currentLanguage as keyof typeof dateFnsLocales] || dateFnsLocales.en
54+
const diff = formatDistance(firstDate, now, { locale, addSuffix: true })
5355
return t('before_event', { conName, diff })
5456
}
5557
}
@@ -66,13 +68,13 @@ const useCountdownTitle = (t: TFunction, now: Date) => {
6668
}
6769

6870
export const CountdownHeader: FC<CountdownHeaderProps> = ({ style }) => {
69-
const { t } = useTranslation('Countdown')
71+
const { t, i18n } = useTranslation('Countdown')
7072
const { t: tAccessibility } = useTranslation('Home', { keyPrefix: 'accessibility' })
7173
const isFocused = useIsFocused()
7274
const now = useNow(isFocused ? 60 : 'static') // Convert to Date
7375

7476
const { width } = useWindowDimensions()
75-
const subtitle = useCountdownTitle(t, now)
77+
const subtitle = useCountdownTitle(t, now, i18n.language)
7678

7779
return (
7880
<View style={[styles.container, style]} role="banner" accessibilityLabel={tAccessibility('countdown_header')} accessibilityHint={tAccessibility('countdown_header_hint')}>

src/i18n/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type Translation = (typeof supportedTranslations)[number]
3131
/**
3232
* Map language codes to date-fns locales.
3333
*/
34-
const dateFnsLocales: Record<string, Locale> = {
34+
export const dateFnsLocales: Record<string, Locale> = {
3535
en: enGB,
3636
nl: nl,
3737
pl: pl,

src/i18n/translations.de.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
},
268268
"Countdown": {
269269
"after_event": "Das war's! Wir hoffen wir sehen Dich nächstes Jahr wieder!",
270-
"before_event": "{{conName}} beginnt in {{diff}}(n)"
270+
"before_event": "{{conName}} beginnt {{diff}}"
271271
},
272272
"Dealer": {
273273
"about": "Infos",

src/i18n/translations.en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
},
269269
"Countdown": {
270270
"after_event": "That was it! We hope to see you again next year!",
271-
"before_event": "{{conName}} will start in {{diff}}"
271+
"before_event": "{{conName}} will start {{diff}}"
272272
},
273273
"Dealer": {
274274
"about": "About",

src/i18n/translations.nl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
},
192192
"Countdown": {
193193
"after_event": "En dat was het weer! Tot volgend jaar!",
194-
"before_event": "{{conName}} begint over {{diff}}"
194+
"before_event": "{{conName}} begint {{diff}}"
195195
},
196196
"Dealer": {
197197
"accessibility": {

src/i18n/translations.pl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
},
151151
"Countdown": {
152152
"after_event": "I to na tyle! Do zobaczenia w przyszłym roku!",
153-
"before_event": "{{conName}} zacznie się za {{diff}}"
153+
"before_event": "{{conName}} zacznie się {{diff}}"
154154
},
155155
"Dealer": {
156156
"about": "Podsumowanie",

0 commit comments

Comments
 (0)