@@ -82,6 +82,27 @@ describe('getCanonicalLocale', () => {
8282 } )
8383} )
8484
85+ describe ( 'getTimezone' , ( ) => {
86+ vi . spyOn ( console , 'debug' ) . mockImplementation ( ( ) => { } )
87+ it ( 'returns the set timezone as it is' , async ( ) => {
88+ mockTimezone ( 'Europe/Berlin' )
89+ expect ( await getTimezone ( ) ) . toEqual ( 'Europe/Berlin' )
90+ } )
91+
92+ it ( 'returns the environment timezone if no timezone is set' , async ( ) => {
93+ mockTimezone ( undefined )
94+ expect ( await getTimezone ( ) ) . toEqual ( process . env . TZ )
95+ } )
96+ } )
97+
98+ describe ( 'setTimezone' , ( ) => {
99+ it ( 'sets the global state' , async ( ) => {
100+ mockTimezone ( 'Europe/Berlin' )
101+ await setTimezone ( 'America/New_York' )
102+ expect ( globalThis . _nc_l10n_timezone ) . toBe ( 'America/New_York' )
103+ } )
104+ } )
105+
85106async function getCanonicalLocale ( ) {
86107 const { getCanonicalLocale } = await import ( '../lib/locale.ts' )
87108 return getCanonicalLocale ( )
@@ -97,6 +118,11 @@ async function getLanguage() {
97118 return getLanguage ( )
98119}
99120
121+ async function getTimezone ( ) {
122+ const { getTimezone } = await import ( '../lib/locale.ts' )
123+ return getTimezone ( )
124+ }
125+
100126async function setLocale ( locale : string ) {
101127 const { setLocale } = await import ( '../lib/locale.ts' )
102128 return setLocale ( locale )
@@ -107,6 +133,11 @@ async function setLanguage(language: string) {
107133 return setLanguage ( language )
108134}
109135
136+ async function setTimezone ( timezone : string ) {
137+ const { setTimezone } = await import ( '../lib/locale.ts' )
138+ return setTimezone ( timezone )
139+ }
140+
110141function mockLanguage ( lang ?: string ) {
111142 // @ts -expect-error - Mocking global state
112143 globalThis . _nc_l10n_language = lang
@@ -118,3 +149,7 @@ function mockLocale(locale?: string) {
118149 delete globalThis . document . documentElement . dataset . locale
119150 }
120151}
152+ function mockTimezone ( timezone ?: string ) {
153+ // @ts -expect-error - Mocking global state
154+ globalThis . _nc_l10n_timezone = timezone
155+ }
0 commit comments