diff --git a/src/params/paramTypes.ts b/src/params/paramTypes.ts index a44609918..dec1e26c9 100644 --- a/src/params/paramTypes.ts +++ b/src/params/paramTypes.ts @@ -57,7 +57,10 @@ export class ParamTypes { return match ? new Date(match[1], match[2] - 1, match[3]) : undefined; }, is: (val) => val instanceof Date && !isNaN(val.valueOf()), - equals(a, b) { return this.is(a) && this.is(b) && a.toISOString() === b.toISOString(); }, + equals(l, r) { + return ['getFullYear', 'getMonth', 'getDate'] + .reduce((acc, fn) => acc && l[fn]() === r[fn](), true) + }, pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/, capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/ }, diff --git a/test/paramSpec.ts b/test/paramSpec.ts new file mode 100644 index 000000000..3402fb765 --- /dev/null +++ b/test/paramSpec.ts @@ -0,0 +1,35 @@ +import {ParamTypes} from "../src/core"; + +describe('parameters', () => { + let types; + + beforeEach(() => types = new ParamTypes()); + + describe('date type', () => { + let dateType; + beforeEach(() => dateType = types.type("date")); + + it('should compare dates', () => { + let date1 = new Date('2010-01-01'); + let date2 = new Date('2010-01-01'); + + let date3 = new Date('2010-02-01'); + + expect(dateType.equals(date1, date2)).toBeTruthy(); + expect(dateType.equals(date1, date3)).toBeFalsy(); + }); + + it('should compare year/month/day only', () => { + let date1 = new Date('2010-01-01'); + date1.setHours(1); + let date2 = new Date('2010-01-01'); + date2.setHours(2); + let date3 = new Date('2010-02-01'); + date3.setHours(3); + + // Failing test case for #2484 + expect(dateType.equals(date1, date2)).toBeTruthy(); + expect(dateType.equals(date1, date3)).toBeFalsy(); + }); + }); +}); \ No newline at end of file