Skip to content

Commit

Permalink
Remove normalization in ShiftTo (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesDebunne authored Jun 5, 2020
1 parent e81600b commit 19b161a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,6 @@ export default class Duration {
vals = this.toObject();
let lastUnit;

normalizeValues(this.matrix, vals);

for (const k of orderedUnits) {
if (units.indexOf(k) >= 0) {
lastUnit = k;
Expand Down
14 changes: 12 additions & 2 deletions test/duration/units.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,32 @@ test("Duration#shiftTo without any units no-ops", () => {
expect(dur.toObject()).toEqual({ years: 3 });
});

test("Duration#shifTo accumulates when rolling up", () => {
test("Duration#shiftTo accumulates when rolling up", () => {
expect(
Duration.fromObject({ minutes: 59, seconds: 183 })
.shiftTo("hours", "minutes", "seconds")
.toObject()
).toEqual({ hours: 1, minutes: 2, seconds: 3 });
});

test("Duration#shifTo keeps unecessary higher-order negative units 0", () => {
test("Duration#shiftTo keeps unnecessary higher-order negative units 0", () => {
expect(
Duration.fromObject({ milliseconds: -100 })
.shiftTo("hours", "minutes", "seconds")
.toObject()
).toEqual({ hours: 0, minutes: 0, seconds: -0.1 });
});

test("Duration#shiftTo does not normalize values", () => {
// Normalizing would convert to { quarters: 4, months: 1, days: 10 }
// which would be converted back to 404 days instead
expect(
Duration.fromObject({ quarters: 0, months: 0, days: 400 })
.shiftTo("days")
.toObject()
).toEqual({ days: 400 });
});

//------
// #normalize()
//-------
Expand Down

0 comments on commit 19b161a

Please sign in to comment.