From 0cf4542ce43862839a0edc6c75bbf50e748ccb57 Mon Sep 17 00:00:00 2001 From: Alan Orozco Date: Tue, 31 Aug 2021 15:23:26 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"=E2=9C=A8=20`amp-date-display`:=20Sup?= =?UTF-8?q?port=20`timeZoneName`=20and=20`timeZoneNameShort`=20(#35828)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 07a5ed30c5adcd46df468952c2b1ab2679862ad3. --- build-system/compile/sources.js | 2 - build-system/test-configs/dep-check-config.js | 3 -- .../amp-date-display/0.1/amp-date-display.js | 12 ----- .../amp-date-display/0.1/amp-date-display.md | 48 +++++++++---------- .../0.1/test/test-amp-date-display.js | 37 -------------- extensions/amp-date-display/1.0/component.js | 10 ---- .../1.0/test/test-amp-date-display.js | 39 --------------- .../1.0/test/test-component.js | 44 ----------------- .../amp-date-display/amp-date-display.md | 48 +++++++++---------- extensions/amp-date-display/format.js | 26 ---------- 10 files changed, 46 insertions(+), 223 deletions(-) delete mode 100644 extensions/amp-date-display/format.js diff --git a/build-system/compile/sources.js b/build-system/compile/sources.js index 4a92f9bcaed6..8e19ddc383a8 100644 --- a/build-system/compile/sources.js +++ b/build-system/compile/sources.js @@ -107,8 +107,6 @@ const CLOSURE_SRC_GLOBS = [ 'extensions/amp-lightbox/1.0/*.js', // For amp-bind in the web worker (ww.js). 'extensions/amp-bind/**/*.js', - // amp-date-display 0.1 and 1.0 share this file. - 'extensions/amp-date-display/format.js', // Needed to access to Variant interface from other extensions 'extensions/amp-experiment/**/*.js', // Needed to access form impl from other extensions diff --git a/build-system/test-configs/dep-check-config.js b/build-system/test-configs/dep-check-config.js index 9697e81b56a4..223b928af413 100644 --- a/build-system/test-configs/dep-check-config.js +++ b/build-system/test-configs/dep-check-config.js @@ -214,9 +214,6 @@ exports.rules = [ 'extensions/amp-lightbox-gallery/1.0/base-element.js->extensions/amp-lightbox/1.0/component.jss.js', 'extensions/amp-lightbox-gallery/1.0/base-element.js->extensions/amp-base-carousel/1.0/component.jss.js', - // versions share these date format helpers - 'extensions/amp-date-display/**->extensions/amp-date-display/format.js', - // Facebook components 'extensions/amp-facebook/1.0/amp-facebook.js->extensions/amp-facebook/0.1/facebook-loader.js', 'extensions/amp-facebook-page/0.1/amp-facebook-page.js->extensions/amp-facebook/0.1/facebook-loader.js', diff --git a/extensions/amp-date-display/0.1/amp-date-display.js b/extensions/amp-date-display/0.1/amp-date-display.js index b065768e672a..1a9699962f00 100644 --- a/extensions/amp-date-display/0.1/amp-date-display.js +++ b/extensions/amp-date-display/0.1/amp-date-display.js @@ -7,7 +7,6 @@ import {Services} from '#service'; import {createCustomEvent} from '../../../src/event-helper'; import {dev, devAssert, user, userAssert} from '../../../src/log'; -import {getTimeZoneName} from '../format'; /** @const {string} */ const TAG = 'amp-date-display'; @@ -39,8 +38,6 @@ const DEFAULT_DATETIME_OPTIONS = { minute: number, second: number, iso: string, - timeZoneName: string, - timeZoneNameShort: string, }} */ let VariablesDef; @@ -271,8 +268,6 @@ export class AmpDateDisplay extends AMP.BaseElement { second: date.getSeconds(), iso: date.toISOString(), localeString: this.getLocaleString_(date, locale, localeOptions), - timeZoneName: getTimeZoneName(date, locale, localeOptions), - timeZoneNameShort: getTimeZoneName(date, locale, localeOptions, 'short'), }; } @@ -313,13 +308,6 @@ export class AmpDateDisplay extends AMP.BaseElement { second: date.getUTCSeconds(), iso: date.toISOString(), localeString: this.getLocaleString_(date, locale, localeOptionsInUTC), - timeZoneName: getTimeZoneName(date, locale, localeOptionsInUTC), - timeZoneNameShort: getTimeZoneName( - date, - locale, - localeOptionsInUTC, - 'short' - ), }; } diff --git a/extensions/amp-date-display/0.1/amp-date-display.md b/extensions/amp-date-display/0.1/amp-date-display.md index ade84590442b..6be7cb84612e 100644 --- a/extensions/amp-date-display/0.1/amp-date-display.md +++ b/extensions/amp-date-display/0.1/amp-date-display.md @@ -39,31 +39,29 @@ for rendering. Refer to the This table lists the format you can specify in your Mustache template: -| Format | Meaning | -| ----------------- | ------------------------------------------------------------- | -| day | 1, 2, ...12, 13, etc. | -| dayName | string, | -| dayNameShort | string, | -| dayPeriod | string, | -| dayTwoDigit | 01, 02, 03, ..., 12, 13, etc. | -| hour | 0, 1, 2, 3, ..., 12, 13, ..., 22, 23 | -| hour12 | 1, 2, 3, ..., 12, 1, 2, ..., 11, 12 | -| hour12TwoDigit | 01, 02, ..., 12, 01, 02, ..., 11, 12 | -| hourTwoDigit | 00, 01, 02, ..., 12, 13, ..., 22, 23 | -| iso | A standard ISO8601 date string e.g. 2019-01-23T15:31:21.213Z, | -| localeString | A string with a language sensitive representation. | -| minute | 0, 1, 2, ..., 58, 59 | -| minuteTwoDigit | 00, 01, 02, ..., 58, 59 | -| month | 1, 2, 3, ..., 12 | -| monthName | Internationalized month name string. | -| monthNameShort | Internationalized abbreviated month name string., | -| monthTwoDigit | 01, 02, ..., 11, 12 | -| second | 0, 1, 2, ..., 58, 59 | -| secondTwoDigit | 00, 01, 02, ..., 58, 59 | -| timeZoneName | Internationalized timezone, like `Pacific Daylight Time` | -| timeZoneNameShort | Internationalized timezone, abbreviated, like `PST` | -| year | 0, 1, 2, ..., 1999, 2000, 2001, etc. | -| yearTwoDigit | 00, 01, 02, ..., 17, 18, 19, ..., 98, 99 | +| Format | Meaning | +| -------------- | ------------------------------------------------------------- | +| day | 1, 2, ...12, 13, etc. | +| dayName | string, | +| dayNameShort | string, | +| dayPeriod | string, | +| dayTwoDigit | 01, 02, 03, ..., 12, 13, etc. | +| hour | 0, 1, 2, 3, ..., 12, 13, ..., 22, 23 | +| hour12 | 1, 2, 3, ..., 12, 1, 2, ..., 11, 12 | +| hour12TwoDigit | 01, 02, ..., 12, 01, 02, ..., 11, 12 | +| hourTwoDigit | 00, 01, 02, ..., 12, 13, ..., 22, 23 | +| iso | A standard ISO8601 date string e.g. 2019-01-23T15:31:21.213Z, | +| minute | 0, 1, 2, ..., 58, 59 | +| minuteTwoDigit | 00, 01, 02, ..., 58, 59 | +| month | 1, 2, 3, ..., 12 | +| monthName | Internationalized month name string. | +| monthNameShort | Internationalized abbreviated month name string., | +| monthTwoDigit | 01, 02, ..., 11, 12 | +| second | 0, 1, 2, ..., 58, 59 | +| secondTwoDigit | 00, 01, 02, ..., 58, 59 | +| year | 0, 1, 2, ..., 1999, 2000, 2001, etc. | +| yearTwoDigit | 00, 01, 02, ..., 17, 18, 19, ..., 98, 99 | +| localeString | A string with a language sensitive representation. | ## Attributes diff --git a/extensions/amp-date-display/0.1/test/test-amp-date-display.js b/extensions/amp-date-display/0.1/test/test-amp-date-display.js index 268957a242d4..20db3fd511da 100644 --- a/extensions/amp-date-display/0.1/test/test-amp-date-display.js +++ b/extensions/amp-date-display/0.1/test/test-amp-date-display.js @@ -70,8 +70,6 @@ describes.realWin( expect(data.secondTwoDigit).to.equal('06'); expect(data.dayPeriod).to.equal('am'); expect(data.localeString).to.equal('Feb 3, 2001, 4:05 AM'); - expect(data.timeZoneName).to.equal('Coordinated Universal Time'); - expect(data.timeZoneNameShort).to.equal('UTC'); }); it('provides all variables in local and English (default)', async () => { @@ -100,43 +98,8 @@ describes.realWin( expect(data.secondTwoDigit).to.equal('06'); expect(data.dayPeriod).to.equal('am'); expect(data.localeString).to.equal('Feb 3, 2001, 4:05 AM'); - // default timezone is affected by running platform, so we just verify - // that both timezone values are present, and that they differ. - // (Another set of tests below verify that the timezone is labelled - // properly in different locales.) - expect(data.timeZoneName).to.be.ok; - expect(data.timeZoneNameShort).to.be.ok; - expect(data.timeZoneName).to.not.equal(data.timeZoneNameShort); }); - const expectedTimeZoneNamesAmericaNewYork = { - 'en': { - timeZoneName: 'Eastern Standard Time', - timeZoneNameShort: 'EST', - }, - 'ja-JP': { - timeZoneName: 'アメリカ東部標準時', - timeZoneNameShort: 'GMT-5', - }, - 'ar-EG': { - timeZoneName: 'التوقيت الرسمي الشرقي لأمريكا الشمالية', - timeZoneNameShort: 'غرينتش-٥', - }, - }; - for (const locale in expectedTimeZoneNamesAmericaNewYork) { - const {timeZoneName, timeZoneNameShort} = - expectedTimeZoneNamesAmericaNewYork[locale]; - it(`provides timeZoneName and timeZoneNameShort with specified TZ (${locale})`, async () => { - element.setAttribute('datetime', '2001-02-03T04:05:06.007Z'); - element.setAttribute('locale', locale); - element.setAttribute('data-options-time-zone', 'America/New_York'); - await element.buildInternal(); - const data = impl.getDataForTemplate_(); - expect(data.timeZoneName).to.equal(timeZoneName); - expect(data.timeZoneNameShort).to.equal(timeZoneNameShort); - }); - } - describe('correctly parses', () => { it('now keyword', async () => { element.setAttribute('datetime', 'now'); diff --git a/extensions/amp-date-display/1.0/component.js b/extensions/amp-date-display/1.0/component.js index dd16d07b24ac..b8ad966fcd41 100644 --- a/extensions/amp-date-display/1.0/component.js +++ b/extensions/amp-date-display/1.0/component.js @@ -6,7 +6,6 @@ import {Wrapper, useRenderer} from '#preact/component'; import {useResourcesNotify} from '#preact/utils'; import {user} from '../../../src/log'; -import {getTimeZoneName} from '../format'; /** @const {string} */ const TAG = 'amp-date-display'; @@ -201,8 +200,6 @@ function getVariablesInLocal( 'second': date.getSeconds(), 'iso': date.toISOString(), 'localeString': getLocaleString_(date, locale, localeOptions), - 'timeZoneName': getTimeZoneName(date, locale, localeOptions), - 'timeZoneNameShort': getTimeZoneName(date, locale, localeOptions, 'short'), }; } @@ -246,12 +243,5 @@ function getVariablesInUTC( 'second': date.getUTCSeconds(), 'iso': date.toISOString(), 'localeString': getLocaleString_(date, locale, localeOptionsInUTC), - 'timeZoneName': getTimeZoneName(date, locale, localeOptionsInUTC), - 'timeZoneNameShort': getTimeZoneName( - date, - locale, - localeOptionsInUTC, - 'short' - ), }; } diff --git a/extensions/amp-date-display/1.0/test/test-amp-date-display.js b/extensions/amp-date-display/1.0/test/test-amp-date-display.js index 3246a9b70df0..d2bbd0af76f0 100644 --- a/extensions/amp-date-display/1.0/test/test-amp-date-display.js +++ b/extensions/amp-date-display/1.0/test/test-amp-date-display.js @@ -63,8 +63,6 @@ describes.realWin( dayPeriod: '{{dayPeriod}}', iso: '{{iso}}', localeString: '{{localeString}}', - timeZoneName: '{{timeZoneName}}', - timeZoneNameShort: '{{timeZoneNameShort}}', }); element.appendChild(template); element.setAttribute('layout', 'nodisplay'); @@ -97,8 +95,6 @@ describes.realWin( expect(data.secondTwoDigit).to.equal('06'); expect(data.dayPeriod).to.equal('am'); expect(data.localeString).to.equal('Feb 3, 2001, 4:05 AM'); - expect(data.timeZoneName).to.equal('Coordinated Universal Time'); - expect(data.timeZoneNameShort).to.equal('UTC'); }); it('renders mustache template with "timestamp-ms"', async () => { @@ -131,43 +127,8 @@ describes.realWin( expect(data.secondTwoDigit).to.equal('06'); expect(data.dayPeriod).to.equal('am'); expect(data.localeString).to.equal('Feb 3, 2001, 4:05 AM'); - // default timezone is affected by running platform, so we just verify - // that both timezone values are present, and that they differ. - // (Another set of tests below verify that the timezone is labelled - // properly in different locales.) - expect(data.timeZoneName).to.be.ok; - expect(data.timeZoneNameShort).to.be.ok; - expect(data.timeZoneName).to.not.equal(data.timeZoneNameShort); }); - const expectedTimeZoneNamesAmericaNewYork = { - 'en': { - timeZoneName: 'Eastern Standard Time', - timeZoneNameShort: 'EST', - }, - 'ja-JP': { - timeZoneName: 'アメリカ東部標準時', - timeZoneNameShort: 'GMT-5', - }, - 'ar-EG': { - timeZoneName: 'التوقيت الرسمي الشرقي لأمريكا الشمالية', - timeZoneNameShort: 'غرينتش-٥', - }, - }; - for (const locale in expectedTimeZoneNamesAmericaNewYork) { - const {timeZoneName, timeZoneNameShort} = - expectedTimeZoneNamesAmericaNewYork[locale]; - it(`provides timeZoneName and timeZoneNameShort with specified TZ (${locale}})`, async () => { - element.setAttribute('datetime', '2001-02-03T04:05:06.007Z'); - element.setAttribute('locale', locale); - element.setAttribute('data-options-time-zone', 'America/New_York'); - win.document.body.appendChild(element); - const data = await getRenderedData(); - expect(data.timeZoneName).to.equal(timeZoneName); - expect(data.timeZoneNameShort).to.equal(timeZoneNameShort); - }); - } - it('render localeString with data-options-time-style', async () => { element.setAttribute('datetime', '2001-02-03T04:05:06.007Z'); element.setAttribute('display-in', 'UTC'); diff --git a/extensions/amp-date-display/1.0/test/test-component.js b/extensions/amp-date-display/1.0/test/test-component.js index 80438d5c8cc2..bfb2d335624f 100644 --- a/extensions/amp-date-display/1.0/test/test-component.js +++ b/extensions/amp-date-display/1.0/test/test-component.js @@ -175,13 +175,6 @@ describes.sandboxed('DateDisplay 1.0 preact component', {}, (env) => { expect(data.second).to.equal('6'); expect(data.secondTwoDigit).to.equal('06'); expect(data.dayPeriod).to.equal('am'); - // default timezone is affected by running platform, so we just verify - // that both timezone values are present, and that they differ. - // (Another set of tests below verify that the timezone is labelled - // properly in different locales.) - expect(data.timeZoneName).to.be.ok; - expect(data.timeZoneNameShort).to.be.ok; - expect(data.timeZoneName).to.not.equal(data.timeZoneNameShort); }); it('provides variables in Czech when "cs" locale is passed', () => { @@ -200,8 +193,6 @@ describes.sandboxed('DateDisplay 1.0 preact component', {}, (env) => { expect(data.monthNameShort).to.equal('úno'); expect(data.dayName).to.equal('sobota'); expect(data.dayNameShort).to.equal('so'); - expect(data.timeZoneName).to.equal('Koordinovaný světový čas'); - expect(data.timeZoneNameShort).to.equal('UTC'); }); it('shows custom locale string when localeOptions is passed', () => { @@ -220,41 +211,6 @@ describes.sandboxed('DateDisplay 1.0 preact component', {}, (env) => { expect(data.localeString).to.equal('上午4:05'); }); - const expectedTimeZoneNamesAmericaNewYork = { - 'en': { - timeZoneName: 'Eastern Standard Time', - timeZoneNameShort: 'EST', - }, - 'ja-JP': { - timeZoneName: 'アメリカ東部標準時', - timeZoneNameShort: 'GMT-5', - }, - 'ar-EG': { - timeZoneName: 'التوقيت الرسمي الشرقي لأمريكا الشمالية', - timeZoneNameShort: 'غرينتش-٥', - }, - }; - for (const locale in expectedTimeZoneNamesAmericaNewYork) { - const {timeZoneName, timeZoneNameShort} = - expectedTimeZoneNamesAmericaNewYork[locale]; - it(`shows timeZoneName and timeZoneNameShort with specified TZ (${locale})`, () => { - const jsx = ( - - ); - const wrapper = mount(jsx); - const data = JSON.parse(wrapper.text()); - expect(data.timeZoneName).to.equal(timeZoneName); - expect(data.timeZoneNameShort).to.equal(timeZoneNameShort); - }); - } - describe('invalid data-options-* settings', () => { it('throws error when invalid localeOptions is passed', () => { const spy = env.sandbox.stub(user(), 'error'); diff --git a/extensions/amp-date-display/amp-date-display.md b/extensions/amp-date-display/amp-date-display.md index c31c7b0007a0..49de37ec9d39 100644 --- a/extensions/amp-date-display/amp-date-display.md +++ b/extensions/amp-date-display/amp-date-display.md @@ -41,31 +41,29 @@ for rendering. Refer to the This table lists the format you can specify in your Mustache template: -| Format | Meaning | -| ----------------- | ------------------------------------------------------------- | -| day | 1, 2, ...12, 13, etc. | -| dayName | string, | -| dayNameShort | string, | -| dayPeriod | string, | -| dayTwoDigit | 01, 02, 03, ..., 12, 13, etc. | -| hour | 0, 1, 2, 3, ..., 12, 13, ..., 22, 23 | -| hour12 | 1, 2, 3, ..., 12, 1, 2, ..., 11, 12 | -| hour12TwoDigit | 01, 02, ..., 12, 01, 02, ..., 11, 12 | -| hourTwoDigit | 00, 01, 02, ..., 12, 13, ..., 22, 23 | -| iso | A standard ISO8601 date string e.g. 2019-01-23T15:31:21.213Z, | -| localeString | A string with a language sensitive representation. | -| minute | 0, 1, 2, ..., 58, 59 | -| minuteTwoDigit | 00, 01, 02, ..., 58, 59 | -| month | 1, 2, 3, ..., 12 | -| monthName | Internationalized month name string. | -| monthNameShort | Internationalized abbreviated month name string., | -| monthTwoDigit | 01, 02, ..., 11, 12 | -| second | 0, 1, 2, ..., 58, 59 | -| secondTwoDigit | 00, 01, 02, ..., 58, 59 | -| timeZoneName | Internationalized timezone, like `Pacific Daylight Time` | -| timeZoneNameShort | Internationalized timezone, abbreviated, like `PST` | -| year | 0, 1, 2, ..., 1999, 2000, 2001, etc. | -| yearTwoDigit | 00, 01, 02, ..., 17, 18, 19, ..., 98, 99 | +| Format | Meaning | +| -------------- | ------------------------------------------------------------- | +| day | 1, 2, ...12, 13, etc. | +| dayName | string, | +| dayNameShort | string, | +| dayPeriod | string, | +| dayTwoDigit | 01, 02, 03, ..., 12, 13, etc. | +| hour | 0, 1, 2, 3, ..., 12, 13, ..., 22, 23 | +| hour12 | 1, 2, 3, ..., 12, 1, 2, ..., 11, 12 | +| hour12TwoDigit | 01, 02, ..., 12, 01, 02, ..., 11, 12 | +| hourTwoDigit | 00, 01, 02, ..., 12, 13, ..., 22, 23 | +| iso | A standard ISO8601 date string e.g. 2019-01-23T15:31:21.213Z, | +| minute | 0, 1, 2, ..., 58, 59 | +| minuteTwoDigit | 00, 01, 02, ..., 58, 59 | +| month | 1, 2, 3, ..., 12 | +| monthName | Internationalized month name string. | +| monthNameShort | Internationalized abbreviated month name string., | +| monthTwoDigit | 01, 02, ..., 11, 12 | +| second | 0, 1, 2, ..., 58, 59 | +| secondTwoDigit | 00, 01, 02, ..., 58, 59 | +| year | 0, 1, 2, ..., 1999, 2000, 2001, etc. | +| yearTwoDigit | 00, 01, 02, ..., 17, 18, 19, ..., 98, 99 | +| localeString | A string with a language sensitive representation. | ### Standalone use outside valid AMP documents diff --git a/extensions/amp-date-display/format.js b/extensions/amp-date-display/format.js deleted file mode 100644 index 8e58ffe07f43..000000000000 --- a/extensions/amp-date-display/format.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @fileoverview Shared implementations of date formatting and variable - * providers for Bento and Classic amp-date-display. - * TODO(alanorozco): Include getVariablesInUTC and getVariablesInLocal. - */ -/** - * @param {!Date} date - * @param {string} locale - * @param {?Object} options - * @param {string=} format ('long' by default) - * @return {string} - * @private - */ -export function getTimeZoneName(date, locale, options, format = 'long') { - if (!Intl?.DateTimeFormat) { - return ''; - } - const formatter = new Intl.DateTimeFormat(locale, { - timeZone: options?.timeZone, - timeZoneName: format, - }); - return ( - formatter.formatToParts(date).find(({type}) => type === 'timeZoneName') - ?.value || '' - ); -}