diff --git a/packages/ruleset/src/utils/date-based-utils.js b/packages/ruleset/src/utils/date-based-utils.js index 2be9ad2f..3ac62615 100644 --- a/packages/ruleset/src/utils/date-based-utils.js +++ b/packages/ruleset/src/utils/date-based-utils.js @@ -50,9 +50,16 @@ function isDateBasedName(name) { // Any name containing `_time_`. /.*_time_.*/, - // Note: not including any name ending in `_time` because it was too easy - // to think of counterexamples. `running_time` in the "movies" API of our - // test document in this project is one of them. + // Not including any name ending in `_time` because there are + // counterexamples, but we still want to catch common date-based + // names that end in `_time`. + /^start_time$/, + /^end_time$/, + /^create_time$/, + /^created_time$/, + /^modify_time$/, + /^modified_time$/, + /^update_time$/, // Any name containing `timestamp`. /.*timestamp.*/, @@ -72,10 +79,10 @@ function isDateBasedName(name) { function isDateBasedValue(value) { const regularExpressions = [ // Includes abbreviated month name. - /\b(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b/, + /^\b(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b/, // Includes full month name. - /\b(January|February|March|April|May|June|July|August|September|October|November|December)\b/, + /^\b(January|February|March|April|May|June|July|August|September|October|November|December)\b/, // Includes date in the format YYYY(./-)MM(./-)DD(T). /\b\d{4}[./-](0?[1-9]|1[012])[./-]([012]?[1-9]|3[01])(\b|T)/, diff --git a/packages/ruleset/test/utils/date-based-utils.test.js b/packages/ruleset/test/utils/date-based-utils.test.js index 23a43ff8..b3d50275 100644 --- a/packages/ruleset/test/utils/date-based-utils.test.js +++ b/packages/ruleset/test/utils/date-based-utils.test.js @@ -23,6 +23,9 @@ describe('Date-based utility functions', () => { // Negative tests. it('should return `false` for non-date time values', () => { + expect(isDateBasedValue('This certificate is good until June 2032')).toBe( + false + ); expect(isDateBasedValue('Octopus')).toBe(false); expect(isDateBasedValue('12345678')).toBe(false); expect(isDateBasedValue('0001-01-2000')).toBe(false); @@ -56,19 +59,19 @@ describe('Date-based utility functions', () => { expect(isDateBasedName('modified')).toBe(true); expect(isDateBasedName('expired')).toBe(true); expect(isDateBasedName('expires')).toBe(true); - // expect(isDateBasedName('start_time')).toBe(true); + expect(isDateBasedName('start_time')).toBe(true); expect(isDateBasedName('start_date')).toBe(true); - // expect(isDateBasedName('end_time')).toBe(true); + expect(isDateBasedName('end_time')).toBe(true); expect(isDateBasedName('end_date')).toBe(true); - // expect(isDateBasedName('create_time')).toBe(true); + expect(isDateBasedName('create_time')).toBe(true); expect(isDateBasedName('create_date')).toBe(true); - // expect(isDateBasedName('created_time')).toBe(true); + expect(isDateBasedName('created_time')).toBe(true); expect(isDateBasedName('created_date')).toBe(true); - // expect(isDateBasedName('modify_time')).toBe(true); + expect(isDateBasedName('modify_time')).toBe(true); expect(isDateBasedName('modify_date')).toBe(true); - // expect(isDateBasedName('modified_time')).toBe(true); + expect(isDateBasedName('modified_time')).toBe(true); expect(isDateBasedName('modified_date')).toBe(true); - // expect(isDateBasedName('update_time')).toBe(true); + expect(isDateBasedName('update_time')).toBe(true); expect(isDateBasedName('update_date')).toBe(true); });