File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
packages/@internationalized/date Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ export {
63
63
today ,
64
64
getHoursInDay ,
65
65
getLocalTimeZone ,
66
+ setLocalTimeZone ,
67
+ resetLocalTimeZone ,
66
68
startOfMonth ,
67
69
startOfWeek ,
68
70
startOfYear ,
Original file line number Diff line number Diff line change @@ -133,14 +133,23 @@ let localTimeZone: string | null = null;
133
133
134
134
/** Returns the time zone identifier for the current user. */
135
135
export function getLocalTimeZone ( ) : string {
136
- // TODO: invalidate this somehow?
137
136
if ( localTimeZone == null ) {
138
137
localTimeZone = new Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
139
138
}
140
139
141
140
return localTimeZone ! ;
142
141
}
143
142
143
+ /** Sets the time zone identifier for the current user. */
144
+ export function setLocalTimeZone ( timeZone : string ) : void {
145
+ localTimeZone = timeZone ;
146
+ }
147
+
148
+ /** Resets the time zone identifier for the current user. */
149
+ export function resetLocalTimeZone ( ) : void {
150
+ localTimeZone = null ;
151
+ }
152
+
144
153
/** Returns the first date of the month for the given date. */
145
154
export function startOfMonth ( date : ZonedDateTime ) : ZonedDateTime ;
146
155
export function startOfMonth ( date : CalendarDateTime ) : CalendarDateTime ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import {
17
17
endOfYear ,
18
18
EthiopicCalendar ,
19
19
getDayOfWeek ,
20
+ getLocalTimeZone ,
20
21
getMinimumDayInMonth ,
21
22
getMinimumMonthInYear ,
22
23
getWeeksInMonth ,
@@ -31,6 +32,8 @@ import {
31
32
maxDate ,
32
33
minDate ,
33
34
PersianCalendar ,
35
+ resetLocalTimeZone ,
36
+ setLocalTimeZone ,
34
37
startOfMonth ,
35
38
startOfWeek ,
36
39
startOfYear ,
@@ -343,4 +346,15 @@ describe('queries', function () {
343
346
expect ( b . compare ( a ) ) . toBeGreaterThan ( 0 ) ;
344
347
} ) ;
345
348
} ) ;
349
+
350
+ describe ( 'getLocalTimeZone' , function ( ) {
351
+ it ( 'gets local time zone' , function ( ) {
352
+ const systemTimeZone = new Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
353
+ expect ( getLocalTimeZone ( ) ) . toBe ( systemTimeZone ) ;
354
+ setLocalTimeZone ( 'America/Denver' ) ;
355
+ expect ( getLocalTimeZone ( ) ) . toBe ( 'America/Denver' ) ;
356
+ resetLocalTimeZone ( ) ;
357
+ expect ( getLocalTimeZone ( ) ) . toBe ( systemTimeZone ) ;
358
+ } ) ;
359
+ } ) ;
346
360
} ) ;
You can’t perform that action at this time.
0 commit comments