From 11e9de2afe47eeac78082130ad18cb1e1f3500a0 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Thu, 24 Oct 2019 18:10:56 -0400 Subject: [PATCH] Remove RRule support (#25230) It doesn't work. Fixes https://github.com/ampproject/amphtml/issues/24297 --- build-system/compile/sources.js | 1 - build-system/externs/amp.extern.js | 13 --- extensions/amp-date-picker/0.1/dates-list.js | 81 ++----------------- .../0.1/test/test-amp-date-picker.js | 8 +- .../0.1/test/test-dates-list.js | 12 +-- extensions/amp-date-picker/amp-date-picker.md | 22 ++--- package.json | 1 - yarn.lock | 14 ---- 8 files changed, 18 insertions(+), 134 deletions(-) diff --git a/build-system/compile/sources.js b/build-system/compile/sources.js index 2d36db0157f9..d9ebaf355905 100644 --- a/build-system/compile/sources.js +++ b/build-system/compile/sources.js @@ -41,7 +41,6 @@ const COMMON_GLOBS = [ 'third_party/webcomponentsjs/ShadowCSS.js', 'node_modules/dompurify/dist/purify.es.js', 'node_modules/promise-pjs/promise.mjs', - 'node_modules/rrule/dist/esm/src/index.js', 'node_modules/web-animations-js/web-animations.install.js', 'node_modules/web-activities/activity-ports.js', 'node_modules/@ampproject/animations/dist/animations.mjs', diff --git a/build-system/externs/amp.extern.js b/build-system/externs/amp.extern.js index ba25c9054cab..4a6cb6a3f58b 100644 --- a/build-system/externs/amp.extern.js +++ b/build-system/externs/amp.extern.js @@ -308,19 +308,6 @@ window.vg; * @type {function(*)} */ let ReactRender = function() {}; -let RRule; -/** - * @param {Date} unusedDt - * @param {boolean} unusedInc - * @return {?Date} - */ -RRule.prototype.before = function(unusedDt, unusedInc) {}; -/** - * @param {Date} unusedDt - * @param {boolean} unusedInc - * @return {?Date} - */ -RRule.prototype.after = function(unusedDt, unusedInc) {}; /** * @dict diff --git a/extensions/amp-date-picker/0.1/dates-list.js b/extensions/amp-date-picker/0.1/dates-list.js index 2e82df1f9814..7770136e8f6d 100644 --- a/extensions/amp-date-picker/0.1/dates-list.js +++ b/extensions/amp-date-picker/0.1/dates-list.js @@ -15,17 +15,15 @@ */ import {requireExternal} from '../../../src/module'; -import {rrulestr} from 'rrule/dist/esm/src/index.js'; /** @enum {string} */ const DateType = { INVALID: 'invalid', - RRULE: 'rrule', DATE: 'date', }; /** - * A class which wraps a list of moment or RRULE dates. + * A class which wraps a list of moment dates. */ export class DatesList { /** @@ -40,11 +38,6 @@ export class DatesList { /** @private @const */ this.moment_ = requireExternal('moment'); - /** @private @const */ - this.rrulestrs_ = dates - .filter(d => this.getDateType_(d) === DateType.RRULE) - .map(d => tryParseRrulestr(d)); - /** @private @const */ this.dates_ = dates .filter(d => this.getDateType_(d) == DateType.DATE) @@ -53,14 +46,14 @@ export class DatesList { } /** - * Determines if the given date is contained within the RRULEs or moment - * dates contained in the date list. + * Determines if the given date is contained within the moment dates + * contained in the date list. * @param {!moment|string} date * @return {boolean} */ contains(date) { const m = this.moment_(date); - return this.matchesDate_(m) || this.matchesRrule_(m); + return this.matchesDate_(m); } /** @@ -79,11 +72,6 @@ export class DatesList { break; } } - const rruleDates = this.rrulestrs_ - .map((/** {RRule} */ rrule) => rrule.after(date)) - .filter(Boolean) - .map(normalizeRruleReturn); - firstDatesAfter.concat(rruleDates); return firstDatesAfter.sort((a, b) => a.toDate() - b.toDate())[0]; } @@ -99,30 +87,7 @@ export class DatesList { } /** - * Determines if any internal RRULE object matches the given date. - * @param {!moment} date - * @return {boolean} - * @private - */ - matchesRrule_(date) { - const nextDate = date - .clone() - .startOf('day') - .add(1, 'day') - .toDate(); - return this.rrulestrs_.some((/** {RRule} */ rrule) => { - const rruleUTCDate = rrule.before(nextDate); - if (!rruleUTCDate) { - return false; - } - const rruleLocalDate = normalizeRruleReturn(rruleUTCDate); - const rruleMoment = this.moment_(rruleLocalDate); - return this.ReactDates_['isSameDay'](rruleMoment, date); - }); - } - - /** - * Distinguish between RRULE dates and moment dates. + * Distinguish between moment dates. * @param {!moment|string} date * @return {!DateType} * @private @@ -132,42 +97,6 @@ export class DatesList { return DateType.DATE; } - const dateStr = /** @type {string} */ (date); - if (tryParseRrulestr(dateStr)) { - return DateType.RRULE; - } - return DateType.INVALID; } } - -/** - * RRULE returns dates as local time formatted at UTC, so the - * Date.prototype.getUTC* methods must be used to create a new date object. - * {@link https://github.com/jakubroztocil/rrule#important-use-utc-dates} - * @param {!Date} rruleDate - * @return {!Date} - */ -function normalizeRruleReturn(rruleDate) { - const year = rruleDate.getUTCFullYear(); - const month = rruleDate.getUTCMonth(); - const day = rruleDate.getUTCDate(); - const hours = rruleDate.getUTCHours(); - const minutes = rruleDate.getUTCMinutes(); - const seconds = rruleDate.getUTCSeconds(); - const ms = rruleDate.getUTCMilliseconds(); - return new Date(year, month, day, hours, minutes, seconds, ms); -} - -/** - * Tries to parse a string into an RRULE object. - * @param {string} str A string which represents a repeating date RRULE spec. - * @return {?JsonObject} - */ -function tryParseRrulestr(str) { - try { - return rrulestr(str); - } catch (e) { - return null; - } -} diff --git a/extensions/amp-date-picker/0.1/test/test-amp-date-picker.js b/extensions/amp-date-picker/0.1/test/test-amp-date-picker.js index f61c03681fe2..4c3cce505236 100644 --- a/extensions/amp-date-picker/0.1/test/test-amp-date-picker.js +++ b/extensions/amp-date-picker/0.1/test/test-amp-date-picker.js @@ -37,8 +37,7 @@ describes.realWin( "templates": [{ "id": "srcTemplate", "dates": [ - "2018-01-01", - "FREQ=WEEKLY;DTSTART=20180101T080000Z;WKST=SU;BYDAY=WE" + "2018-01-01" ] }, { "id": "defaultTemplate" @@ -233,7 +232,7 @@ describes.realWin( describe('templates', () => { describe('element templates', () => { - it('should parse RRULE and date templates', () => { + it('should parse date templates', () => { const template = createDateTemplate('{{template}}', { dates: '2018-01-01', }); @@ -246,7 +245,7 @@ describes.realWin( }); describe('src templates', () => { - it('should parse RRULE and date templates', function() { + it('should parse date templates', function() { this.timeout(4000); const template = createDateTemplate('{{val}}', { dates: '2018-01-01', @@ -264,7 +263,6 @@ describes.realWin( ); expect(srcTemplates[0].dates.contains('2018-01-01')).to.be.true; expect(srcTemplates[0].dates.contains('2018-01-02')).to.be.false; - expect(srcTemplates[0].dates.contains('2018-01-03')).to.be.true; expect(srcTemplates[0].template).to.equal(template); expect(srcDefaultTemplate).to.equal(defaultTemplate); }); diff --git a/extensions/amp-date-picker/0.1/test/test-dates-list.js b/extensions/amp-date-picker/0.1/test/test-dates-list.js index 5def5b0bd8fe..43d94314f3e9 100644 --- a/extensions/amp-date-picker/0.1/test/test-dates-list.js +++ b/extensions/amp-date-picker/0.1/test/test-dates-list.js @@ -21,18 +21,14 @@ import {requireExternal} from '../../../../src/module'; describes.sandboxed('DatesList', {}, () => { const moment = requireExternal('moment'); - it('should accept date strings and RRULE strings', function() { + it('should accept date strings', function() { this.timeout(3000); const containedDate = '09/04/1998'; const notContainedDate = '09/03/1998'; - const containedRrule = - 'FREQ=WEEKLY;COUNT=10;DTSTART=20180101T000000Z;WKST=SU;BYDAY=TU,SA'; - const matchesRrule = '01/02/2018'; - const datesList = new DatesList([containedDate, containedRrule]); + const datesList = new DatesList([containedDate]); expect(datesList.contains(containedDate)).to.be.true; expect(datesList.contains(notContainedDate)).to.be.false; - expect(datesList.contains(matchesRrule)).to.be.true; }); it('should accept moment objects', () => { @@ -66,10 +62,8 @@ describes.sandboxed('DatesList', {}, () => { const containedDate = '09/04/1998'; const dateBefore = '01/01/1998'; // const notContainedDate = '09/03/1998'; - const containedRrule = - 'FREQ=WEEKLY;COUNT=10;DTSTART=20180101T000000Z;WKST=SU;BYDAY=TU,SA'; // const matchesRrule = '01/02/2018'; - const datesList = new DatesList([containedDate, containedRrule]); + const datesList = new DatesList([containedDate]); const result = datesList.firstDateAfter(dateBefore); diff --git a/extensions/amp-date-picker/amp-date-picker.md b/extensions/amp-date-picker/amp-date-picker.md index 2f4d0272dbc3..8fb83e9216cf 100644 --- a/extensions/amp-date-picker/amp-date-picker.md +++ b/extensions/amp-date-picker/amp-date-picker.md @@ -207,20 +207,12 @@ and the user can select a date range with a starting date and ending date. ## Date formats -`amp-date-picker` attributes accept dates in ISO 8601 and RFC 5545 RRULE formats. +`amp-date-picker` attributes accept dates in ISO 8601. [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) formats dates as `YYYY-MM-DD` and is the standard for sharing dates between electronic systems. For example, ISO 8601 formats the date February 28 2018 as `2018-02-28`. -[RFC 5545 Recurrence Rules (RRULEs)](https://icalendar.org/iCalendar-RFC-5545/3-3-10-recurrence-rule.html) -standardize a format for specifying repeating dates. -For example, RFC 5545 formats Halloween as `RRULE:FREQ=YEARLY;BYMONTH=10;BYMONTHDAY=31`. -More complex dates are also possible, such as the United States Thanksgiving holiday, -which is every November on the fourth Thursday: `RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=+4TH`. -The API is not friendly to memorize, but there are various -[RRULE generators](https://jakubroztocil.github.io/rrule) available online. - ## Attributes ##### mode @@ -381,11 +373,11 @@ The day to specify as the first day of the week (0-6). The default value is `"0" ##### blocked -A space-separated list of ISO 8601 dates or RFC 5545 RRULE repeating dates to prevent the user from selecting on the calendar. +A space-separated list of ISO 8601 dates to prevent the user from selecting on the calendar. ##### highlighted -A space-separated list of ISO 8601 dates or RFC 5545 RRULE repeating dates to specially style as highlighted to draw the user's attention. +A space-separated list of ISO 8601 dates to specially style as highlighted to draw the user's attention. Default styling is a blue dot on the date. ##### day-size @@ -430,7 +422,7 @@ The following table lists the properties that you can specify in the JSON data: blocked -An array of ISO 8601 single dates or RFC 5545 RRULE repeating dates to render as blocked in the calendar view. The user is prevented from selecting these dates. +An array of ISO 8601 single dates to render as blocked in the calendar view. The user is prevented from selecting these dates. date @@ -442,7 +434,7 @@ The following table lists the properties that you can specify in the JSON data: highlighted -An array of ISO 8601 single dates or RFC 5545 RRULE repeating dates to render as highlighted in the calendar view. +An array of ISO 8601 single dates to render as highlighted in the calendar view. startDate @@ -459,7 +451,7 @@ The `src` attribute may be updated after a user gesture with [`amp-bind`](https: ###### template definition objects -The `dates` property is an array of ISO 8601 single dates or RFC 5545 RRULE repeating dates. +The `dates` property is an array of ISO 8601 single dates. The `id` property specifies the `id` of a template that the date picker can use to render the specified dates in the calendar view. @@ -766,7 +758,7 @@ Using `src` prevents chached AMP documents from showing out-of-date information. A `date-template` must have a `dates` or `default` attribute. -- **dates**: A space-separated list of ISO 8601 single dates or RFC 5545 RRULE repeating dates. +- **dates**: A space-separated list of ISO 8601 single dates. The template content will render for the dates matching the dates in the attribute. - **default**: If the `default` attribute is present, the template content will render for all dates not matching an existing template. diff --git a/package.json b/package.json index 20caa25cd8a7..d3ca57a71eca 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "promise-pjs": "1.1.4", "prop-types": "15.7.2", "react-dates": "15.5.3", - "rrule": "2.6.2", "web-activities": "1.13.0", "web-animations-js": "2.3.1" }, diff --git a/yarn.lock b/yarn.lock index db29f17a15e9..579cdf89e95f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8940,11 +8940,6 @@ lru-queue@0.1: dependencies: es5-ext "~0.10.2" -luxon@^1.3.3: - version "1.19.3" - resolved "https://registry.yarnpkg.com/luxon/-/luxon-1.19.3.tgz#86c04a1395529b4386ae235a8fe16d0a82a0695b" - integrity sha512-YwTDjGRQC0QC9Iya2g2eKZfgEFqRId4ZoLHORQcfTMB/5xrTx427V7ZPjQJ1vzvhA2vJfG2bh1Kv8V8IFMWCUA== - magic-string@0.25.4: version "0.25.4" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.4.tgz#325b8a0a79fc423db109b77fd5a19183b7ba5143" @@ -11968,15 +11963,6 @@ rocambole@0.7.0: dependencies: esprima "^2.1" -rrule@2.6.2: - version "2.6.2" - resolved "https://registry.yarnpkg.com/rrule/-/rrule-2.6.2.tgz#f175c6c0b20d6f798739e4e1d979ffb3d79589e8" - integrity sha512-xL38CM1zOYOIp4OO8hdD6zHH5UdR9siHMvPiv+CCSh7o0LYJ0owg87QcFW7GXJ0PfpLBHjanEMvvBjJxbRhAcQ== - dependencies: - tslib "^1.9.0" - optionalDependencies: - luxon "^1.3.3" - rsvp@^4.8.4: version "4.8.5" resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"