Skip to content

WEBDEV-7387 fix for GMT timezone #442

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/tiles/list/tile-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export class TileList extends BaseTileComponent {
if (isFirstMillisecondOfUTCYear(date)) {
format = 'year-only';
}

return this.metadataTemplate(formatDate(date, format), msg('Published'));
}

Expand Down
12 changes: 11 additions & 1 deletion src/utils/format-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ export function formatDate(
// the date is already in UTC timezone so we should not add timeZone here again.
const options: Intl.DateTimeFormatOptions = {};

console.log('defined formatDate: ', date);
switch (format) {
case 'year-only':
// If we're only using the year, ensure we output the correct UTC year and not
// the local year. If the local timezone is used, we can get strange off-by-one
// errors due to quirks of timezone handling for older years.
return `${date.getUTCFullYear()}`;
// return `${date.getUTCFullYear()}`;
// Get the UTC year
const utcYear = Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
);
console.log('return yearonly: ', new Date(utcYear));
// Return the UTC year
return `${new Date(utcYear).getUTCFullYear()}`;
case 'short':
options.month = 'short';
options.year = 'numeric';
Expand Down
Loading