From 7aae376850a651a9fa05df707fb5e0266ad61e42 Mon Sep 17 00:00:00 2001 From: "Cezar Carvalhaes (he/him)" Date: Tue, 1 Feb 2022 22:37:46 -0500 Subject: [PATCH] fix: reset remainder after its been used and update date_range_lesser test (#223) --- src/operators/expression/date/dateFromParts.ts | 4 +++- test/operators/expression/date.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/operators/expression/date/dateFromParts.ts b/src/operators/expression/date/dateFromParts.ts index fc97af16..a4cbba43 100644 --- a/src/operators/expression/date/dateFromParts.ts +++ b/src/operators/expression/date/dateFromParts.ts @@ -32,7 +32,6 @@ export function $dateFromParts( options?: Options ): AnyVal { const args = computeValue(obj, expr, null, options) as DateArgs; - const minuteOffset = parseTimezone(args.timezone); // assign default and adjust value ranges of the different parts @@ -46,6 +45,9 @@ export function $dateFromParts( // add remainder from previous part. units should already be correct let part = ((args[k] as number) || 0) + remainder; + // reset remainder now that it's been used. + remainder = 0; + // 1. compute the remainder for the next part // 2. adjust the current part to a valid range // 3. assign back to 'args' diff --git a/test/operators/expression/date.test.ts b/test/operators/expression/date.test.ts index 7f767523..b4e43333 100644 --- a/test/operators/expression/date.test.ts +++ b/test/operators/expression/date.test.ts @@ -276,7 +276,7 @@ describe("Date Operators: $dateFromParts", () => { $dateFromParts: { year: 2017, month: 14, day: 1, hour: 12 }, }, date_range_lesser: { - $dateFromParts: { year: 2017, month: 0, day: 1, hour: 12 }, + $dateFromParts: { year: 2017, month: 2, day: 0, hour: 12 }, }, }, }, @@ -291,7 +291,7 @@ describe("Date Operators: $dateFromParts", () => { }); it("can apply $dateFromParts with date parts below range of values", () => { - expect(result.date_range_lesser).toEqual(new Date("2016-12-01T12:00:00Z")); + expect(result.date_range_lesser).toEqual(new Date("2017-01-31T12:00:00Z")); }); it("can apply $dateFromParts with timezone", () => {