mirror of
https://github.com/coder/coder.git
synced 2025-07-21 01:28:49 +00:00
fix(site): correctly interpret timezone based on offset in formatOffset
(#10797)
Fixes #10784
This commit is contained in:
committed by
GitHub
parent
9b6433e3a7
commit
6b3f599438
@ -791,14 +791,14 @@ function toISOLocal(d: Date, offset: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatOffset(offset: number): string {
|
function formatOffset(offset: number): string {
|
||||||
const isPositive = offset >= 0;
|
// A negative offset means that this is a positive timezone, e.g. GMT+2 = -120.
|
||||||
|
const isPositiveTimezone = offset <= 0;
|
||||||
const absoluteOffset = Math.abs(offset);
|
const absoluteOffset = Math.abs(offset);
|
||||||
const hours = Math.floor(absoluteOffset / 60);
|
const hours = Math.floor(absoluteOffset / 60);
|
||||||
const minutes = Math.abs(offset) % 60;
|
const minutes = Math.abs(offset) % 60;
|
||||||
const formattedHours = `${isPositive ? "+" : "-"}${String(hours).padStart(
|
const formattedHours = `${isPositiveTimezone ? "+" : "-"}${String(
|
||||||
2,
|
hours,
|
||||||
"0",
|
).padStart(2, "0")}`;
|
||||||
)}`;
|
|
||||||
const formattedMinutes = String(minutes).padStart(2, "0");
|
const formattedMinutes = String(minutes).padStart(2, "0");
|
||||||
return `${formattedHours}:${formattedMinutes}`;
|
return `${formattedHours}:${formattedMinutes}`;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user