diff --git a/src/relative-time-element.ts b/src/relative-time-element.ts index 4ed38b1..2daf2d1 100644 --- a/src/relative-time-element.ts +++ b/src/relative-time-element.ts @@ -516,7 +516,8 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor const year = this.getAttribute('year') if (year === 'numeric' || year === '2-digit') return year - if (!this.hasAttribute('year') && new Date().getUTCFullYear() !== this.date?.getUTCFullYear()) { + const date = this.date + if (!this.hasAttribute('year') && !(date && this.#isCurrentYear(date, this.#lang, this.timeZone))) { return 'numeric' } } diff --git a/test/relative-time.js b/test/relative-time.js index 14fdd8c..563a134 100644 --- a/test/relative-time.js +++ b/test/relative-time.js @@ -3274,5 +3274,15 @@ suite('relative-time', function () { assert.equal(time.shadowRoot.textContent, 'Wed, Jan 1, 2020, 9:00:00 PM') document.documentElement.removeAttribute('time-zone') }) + + test('shows the year when the date is in a past year in the time-zone', async () => { + freezeTime(new Date('2023-06-15T12:00:00.000Z')) + const el = document.createElement('relative-time') + el.setAttribute('datetime', '2023-01-01T02:00:00.000Z') + el.setAttribute('time-zone', 'America/New_York') + el.setAttribute('format', 'datetime') + await Promise.resolve() + assert.equal(el.shadowRoot.textContent, 'Sat, Dec 31, 2022') + }) }) })