11import dayjs , { type Dayjs } from "dayjs"
22import weekOfYear from "dayjs/plugin/weekOfYear"
33import weekYear from "dayjs/plugin/weekYear"
4+ import localeData from "dayjs/plugin/localeData"
45dayjs . extend ( weekOfYear )
56dayjs . extend ( weekYear )
7+ dayjs . extend ( localeData )
68import type React from "react"
79import { Fragment , forwardRef } from "react"
810
11+ // if more locales then english and germans are needed, we need to enable them first here
12+ import "dayjs/locale/de"
13+ //import "dayjs/locale/es"
14+ //import "dayjs/locale/fr"
15+ //import "dayjs/locale/it"
16+ //import "dayjs/locale/nl"
17+
918import type { TimeTableViewType } from "./TimeTable"
1019import type { TimeFrameDay } from "./TimeTableConfigStore"
1120
12- const headerTimeSlotFormat = "HH:mm"
21+ const headerTimeSlotFormat : { [ viewType in TimeTableViewType ] : string } = {
22+ hours : "HH:mm" ,
23+ days : "dd HH:mm" ,
24+ weeks : "HH:mm" ,
25+ months : "HH:mm" ,
26+ years : "HH:mm" ,
27+ }
1328
1429export function headerText (
1530 tsStart : Dayjs ,
@@ -49,6 +64,7 @@ type TimeTableHeaderProps = {
4964 /** a dayjs format string */
5065 dateHeaderTextFormat ?: string
5166 weekStartsOnSunday : boolean
67+ locale ?: "en" | "de"
5268}
5369
5470export const LPTimeTableHeader = forwardRef ( function TimeTableHeader (
@@ -63,9 +79,15 @@ export const LPTimeTableHeader = forwardRef(function TimeTableHeader(
6379 timeFrameDay,
6480 dateHeaderTextFormat,
6581 weekStartsOnSunday,
82+ locale,
6683 } : TimeTableHeaderProps ,
6784 tableHeaderRef : React . Ref < HTMLTableSectionElement > ,
6885) {
86+ const currentLocale = dayjs . locale ( )
87+ if ( locale && locale !== currentLocale ) {
88+ dayjs . locale ( locale )
89+ }
90+
6991 const viewTypeUnit = viewType === "hours" ? "days" : viewType
7092 const daysOrWeeksOrMonths = [
7193 ...new Set (
@@ -217,7 +239,9 @@ export const LPTimeTableHeader = forwardRef(function TimeTableHeader(
217239 } ${ showTimeSlotHeader ? "pt-1" : "" } `}
218240 >
219241 { showTimeSlotHeader
220- ? slot . format ( headerTimeSlotFormat )
242+ ? slot . format (
243+ headerTimeSlotFormat [ viewType ] ,
244+ )
221245 : undefined }
222246 </ th >
223247 )
0 commit comments