Skip to content

Commit 2bfbb3b

Browse files
authored
docs: update time zone docs, add Asia/Saigon examples (#2878)
* docs: update time zone docs, add Asia/Saigon examples Signed-off-by: gpbl <[email protected]> * Export example Signed-off-by: gpbl <[email protected]> * Update test description Signed-off-by: gpbl <[email protected]> --------- Signed-off-by: gpbl <[email protected]>
1 parent 14494d6 commit 2bfbb3b

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
3+
import { render, screen } from "@/test/render";
4+
import { AsiaSaigonTimezone } from "./AsiaSaigonTimezone";
5+
6+
beforeEach(() => {
7+
render(<AsiaSaigonTimezone />);
8+
});
9+
10+
test.skip("the first row should display 7 days", () => {
11+
expect(
12+
screen.getAllByRole("row")[0].querySelectorAll("[role='gridcell']"),
13+
).toHaveLength(7);
14+
});

examples/AsiaSaigonTimezone.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from "react";
2+
3+
import { DayPicker } from "react-day-picker";
4+
5+
export function AsiaSaigonTimezone() {
6+
return <DayPicker defaultMonth={new Date(1900, 11)} timeZone="Asia/Saigon" />;
7+
}

examples/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from "./Animate";
33
export * from "./AnimateCSSVars";
44
export * from "./AnimateRange";
55
export * from "./AnimateRtl";
6+
export * from "./AsiaSaigonTimezone";
67
export * from "./AutoFocus";
78
export * from "./BroadcastCalendar";
89
export * from "./Buddhist";

website/docs/localization/setting-time-zone.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ By default, DayPicker uses the browser’s local time zone. You can override thi
99

1010
The time zone can be specified as either an [IANA time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) identifier or a UTC offset.
1111

12-
| Prop Name | Type | Description |
13-
| ---------- | -------- | ------------------------------------------------- |
14-
| `timeZone` | `string` | The time zone to use when rendering the calendar. |
12+
| Prop Name | Type | Description |
13+
| ---------- | -------- | ------------------------------------------------------ |
14+
| `timeZone` | `string` | The IANA time zone to use when rendering the calendar. |
1515

1616
```tsx
1717
<DayPicker timeZone="UTC" /> // Coordinated Universal Time
1818
<DayPicker timeZone="Pacific/Honolulu" /> // US Hawaii Time
1919
<DayPicker timeZone="Europe/Paris" /> // Central European Time
20+
<DayPicker timeZone="UTC+2" /> // UTC plus 2 hours
21+
<DayPicker timeZone="UTC-5" /> // UTC minus 5 hours
2022
```
2123

2224
## Working with time-zoned dates
2325

24-
When working with time zones, use the `TZDate` object exported by `react-day-picker` instead of the native `Date` object. `TZDate` ensures the calendar reads and writes dates in the time zone you specify.
26+
When working with time zones, use the `TZDate` object exported by `react-day-picker` instead of the native `Date` object. `TZDate` ensures your user interface always reads and writes dates in the time zone you specify.
2527

2628
```tsx
2729
import React, { useState } from "react";
@@ -38,6 +40,11 @@ export function TimeZone() {
3840
timeZone={timeZone}
3941
selected={selected}
4042
onSelect={setSelected}
43+
footer={
44+
selected
45+
? selected.toString()
46+
: `Pick a day to see it is in ${timeZone} time zone.`
47+
}
4148
/>
4249
);
4350
}

website/src/components/Playground/LocalizationFieldset.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const timeZones = [
4242
"Asia/Dubai",
4343
"Asia/Hong_Kong",
4444
"Asia/Kolkata",
45+
"Asia/Saigon",
4546
"Asia/Seoul",
4647
"Asia/Shanghai",
4748
"Asia/Singapore",

0 commit comments

Comments
 (0)