From 6b5ab75252ab2eebc4bc285bae22b79ce89b095e Mon Sep 17 00:00:00 2001 From: clau <1281581+dualcnhq@users.noreply.github.com> Date: Fri, 25 Apr 2025 08:00:05 +0800 Subject: [PATCH] initial fix for GMT timezone --- src/tiles/list/tile-list.ts | 1 - src/utils/format-date.ts | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tiles/list/tile-list.ts b/src/tiles/list/tile-list.ts index 99b0fa1a4..d450d7d36 100644 --- a/src/tiles/list/tile-list.ts +++ b/src/tiles/list/tile-list.ts @@ -218,7 +218,6 @@ export class TileList extends BaseTileComponent { if (isFirstMillisecondOfUTCYear(date)) { format = 'year-only'; } - return this.metadataTemplate(formatDate(date, format), msg('Published')); } diff --git a/src/utils/format-date.ts b/src/utils/format-date.ts index 18b88f523..129796a8e 100644 --- a/src/utils/format-date.ts +++ b/src/utils/format-date.ts @@ -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';