Skip to content

Commit 6b5ab75

Browse files
committed
initial fix for GMT timezone
1 parent 2a1e013 commit 6b5ab75

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/tiles/list/tile-list.ts

-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ export class TileList extends BaseTileComponent {
218218
if (isFirstMillisecondOfUTCYear(date)) {
219219
format = 'year-only';
220220
}
221-
222221
return this.metadataTemplate(formatDate(date, format), msg('Published'));
223222
}
224223

src/utils/format-date.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ export function formatDate(
1818
// the date is already in UTC timezone so we should not add timeZone here again.
1919
const options: Intl.DateTimeFormatOptions = {};
2020

21+
console.log('defined formatDate: ', date);
2122
switch (format) {
2223
case 'year-only':
2324
// If we're only using the year, ensure we output the correct UTC year and not
2425
// the local year. If the local timezone is used, we can get strange off-by-one
2526
// errors due to quirks of timezone handling for older years.
26-
return `${date.getUTCFullYear()}`;
27+
// return `${date.getUTCFullYear()}`;
28+
// Get the UTC year
29+
const utcYear = Date.UTC(
30+
date.getFullYear(),
31+
date.getMonth(),
32+
date.getDate(),
33+
);
34+
console.log('return yearonly: ', new Date(utcYear));
35+
// Return the UTC year
36+
return `${new Date(utcYear).getUTCFullYear()}`;
2737
case 'short':
2838
options.month = 'short';
2939
options.year = 'numeric';

0 commit comments

Comments
 (0)