Skip to content

Commit

Permalink
fix fickle test
Browse files Browse the repository at this point in the history
  • Loading branch information
icambron committed Dec 31, 2018
1 parent 6516222 commit 709f8ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/datetime.js
Expand Up @@ -1679,7 +1679,10 @@ export default class DateTime {
*/
diff(otherDateTime, unit = "milliseconds", opts = {}) {
if (!this.isValid || !otherDateTime.isValid) {
return Duration.invalid(this.invalid || otherDateTime.invalid);
return Duration.invalid(
this.invalid || otherDateTime.invalid,
"created by diffing an invalid DateTime"
);
}

const durOpts = Object.assign(
Expand Down
10 changes: 5 additions & 5 deletions test/datetime/relative.test.js
Expand Up @@ -43,14 +43,14 @@ test("DateTime#toRelative takes a round argument", () => {
});

test("DateTime#toRelative takes a unit argument", () => {
const base = DateTime.fromObject({ year: 1983, month: 10, day: 14 });
const base = DateTime.fromObject({ year: 2018, month: 10, day: 14, zone: "UTC" });
expect(base.plus({ months: 15 }).toRelative({ base, unit: "months" })).toBe("in 15 months");
expect(base.minus({ months: 15 }).toRelative({ base, unit: "months" })).toBe("15 months ago");
expect(base.plus({ months: 6 }).toRelative({ base, unit: "years", round: false })).toBe(
"in 0.5 years"
expect(base.plus({ months: 3 }).toRelative({ base, unit: "years", round: false })).toBe(
"in 0.25 years"
);
expect(base.minus({ months: 6 }).toRelative({ base, unit: "years", round: false })).toBe(
"0.5 years ago"
expect(base.minus({ months: 3 }).toRelative({ base, unit: "years", round: false })).toBe(
"0.25 years ago"
);
});

Expand Down

0 comments on commit 709f8ec

Please sign in to comment.