Skip to content

Commit 4ae9959

Browse files
committed
Just use shortOffset
longOffset vs. shortOffset doesn't matter. It's just for UI purposes, as formatUtils formatTimeZone takes the time zone names to derive the display, not offset. Also fixed match bug where for GMT+0, Intl.DateTimeFormat only prints "GMT", not e.g. "GMT+0". Signed-off-by: Brendan Miller <6900229+bhmiller@users.noreply.github.com>
1 parent 170ded0 commit 4ae9959

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

python/ray/dashboard/client/src/common/timezone.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
const getCurrentUTCOffset = (timeZone: string) => {
22
try {
33
const date = new Date();
4-
// Ideally this would be longOffset, but it's not supported in used version of node
54
const formatter = new Intl.DateTimeFormat("en-US", {
65
timeZone,
76
timeZoneName: "shortOffset",
87
});
9-
// Extract the GMT offset part from the formatted string and ensure it has minutes
8+
// Extract the GMT offset part from the formatted string
109
const formatted = formatter.format(date);
11-
const match = formatted.match(/GMT[+-]\d{1,2}(?::\d{2})?/);
12-
if (match) {
13-
// Ensure the offset has minutes and hours are padded (e.g., convert GMT+5 to GMT+05:00)
14-
const offset = match[0];
15-
if (!offset.includes(":")) {
16-
return offset.replace(
17-
/([+-])(\d{1,2})$/,
18-
(_, sign, hours) => `${sign}${hours.padStart(2, "0")}:00`,
19-
);
20-
}
21-
return offset.replace(
22-
/([+-])(\d{1,2}):/,
23-
(_, sign, hours) => `${sign}${hours.padStart(2, "0")}:`,
24-
);
25-
}
26-
return "";
10+
const match = formatted.match(/GMT([+-]\d{1,2}(?::\d{2})?)?/);
11+
return match ? match[0] : "";
2712
} catch (e) {
2813
console.warn(`Error getting UTC offset for ${timeZone}:`, e);
2914
return "";

python/ray/dashboard/client/src/components/SearchComponent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ export const SearchTimezone = ({
122122
});
123123

124124
const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
125-
const browserTz = timezones.find((t) => t.value === browserTimezone);
126-
if (browserTz) {
125+
const browserUtc = timezones.find((t) => t.value === browserTimezone)?.utc;
126+
if (browserUtc) {
127127
options.unshift({
128128
value: browserTimezone,
129-
utc: browserTz.utc,
129+
utc: browserUtc,
130130
group: "System",
131131
country: "Browser Time",
132132
});

0 commit comments

Comments
 (0)