Skip to content

Commit

Permalink
Fixing issue #1165 and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoAugustoPansani committed Apr 21, 2022
1 parent aa6ab8b commit c55a8be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/impl/diff.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Duration from "../duration.js";

function dayDiff(earlier, later) {
const utcDayStart = (dt) => dt.toUTC(0, { keepLocalTime: true }).startOf("day").valueOf(),
const utcDayStart = (dt) => dt.toUTC(0).startOf("day").valueOf(),
ms = utcDayStart(later) - utcDayStart(earlier);
return Math.floor(Duration.fromMillis(ms).as("days"));
}
Expand Down
10 changes: 10 additions & 0 deletions test/datetime/diff.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ test("DateTime#diff results works when needing to backtrack months", () => {
expect(diff.days).toBe(1);
});

test("DateTime#diff works when date has a zone object", () => {
const start = DateTime.fromISO("2022-05-05T23:00", { zone: "UTC" });
const end = DateTime.fromISO("2022-05-10T00:00", { zone: "Europe/Madrid" });

const diff = end.diff(start, ["days", "hours", "minutes"]).toObject();
expect(diff.days).toBe(3);
expect(diff.hours).toBe(23);
expect(diff.minutes).toBe(0);
});

//------
// diffNow
//-------
Expand Down

0 comments on commit c55a8be

Please sign in to comment.