Skip to content

docs: account for time zones and DST better in release date #11453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions docs/users/Releases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,44 @@ import useIsBrowser from '@docusaurus/useIsBrowser';

export function LocalTimeOfRelease() {
const isBrowser = useIsBrowser();
// An arbitrary Monday at 17:00 UTC.
const date = new Date('1970-01-05T17:00Z');
const formatted = date.toLocaleTimeString('en-US', {
if (!isBrowser) {
// An arbitrary Monday at 17:00 UTC.
const arbitraryMonday = new Date('1970-01-05T17:00Z');
return arbitraryMonday.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
timeZoneName: 'short',
timeZone: 'UTC',
});
}
const now = new Date();
const daysAgoToMonday = (now.getUTCDay() + 6) % 7;
// Calculate the previous Monday at 17:00 UTC.
const previousReleaseDate = new Date(
Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate() - daysAgoToMonday,
17,
),
);
// This will happen if the current time is before 17:00 UTC on Monday.
if (previousReleaseDate > now) {
previousReleaseDate.setUTCDate(previousReleaseDate.getUTCDate() - 7);
}
// Next release is 7 days later.
const nextReleaseDate = new Date(previousReleaseDate.getTime());
nextReleaseDate.setUTCDate(previousReleaseDate.getUTCDate() + 7);
// If we're near a DST time change, we want to display the time of the release that has the same UTC offset as now.
// If, for some reason, neither does, just display the local time of the next release.
const releaseWithSameUtcOffset =
[nextReleaseDate, previousReleaseDate].find(
date => date.getTimezoneOffset() === now.getTimezoneOffset(),
) ?? nextReleaseDate;
const formatted = releaseWithSameUtcOffset.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
timeZoneName: 'short',
timeZone: isBrowser ? undefined : 'UTC',
});
// Specify the day of week if it's not a Monday.
const dayNames = [
Expand All @@ -26,8 +57,10 @@ export function LocalTimeOfRelease() {
'Friday',
'Saturday',
];
if (date.getDay() !== date.getUTCDay()) {
return `${dayNames[date.getDay()]}s at ${formatted}`;
if (
releaseWithSameUtcOffset.getDay() !== releaseWithSameUtcOffset.getUTCDay()
) {
return `${dayNames[releaseWithSameUtcOffset.getDay()]}s at ${formatted}`;
}
return formatted;
}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy