Skip to content

Commit

Permalink
fix: reset remainder after its been used and update date_range_lesser…
Browse files Browse the repository at this point in the history
… test (#223)
  • Loading branch information
cezarcarvalhaes authored Feb 2, 2022
1 parent b70467e commit 7aae376
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/operators/expression/date/dateFromParts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions test/operators/expression/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
},
},
Expand All @@ -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", () => {
Expand Down

0 comments on commit 7aae376

Please sign in to comment.