Skip to content

Commit 650bafd

Browse files
committed
Fix handling of milliseconds
1 parent 46e1ecd commit 650bafd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

__tests__/calculations.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ describe("DateTime calculations", () => {
348348
expect(utils.getDiff(utils.date("2018-10-30"), "2018-10-29", "seconds")).toBe(
349349
24 * 3600
350350
);
351+
expect(utils.getDiff(utils.date("2018-10-30"), "2018-10-29", "milliseconds")).toBe(
352+
24 * 3600 * 1000
353+
);
351354
});
352355

353356
utilsTest("mergeDateAndTime", (date, utils, lib) => {

packages/js-joda/src/js-joda-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ export default class JsJodaUtils implements IUtils<Temporal> {
234234
} else if (value instanceof LocalDate && comparingDate instanceof LocalDate && !chronoUnit.isDateBased()) {
235235
// Convert days using the estimated duration of one day.
236236
const days = ChronoUnit.DAYS.between(comparingDate, value);
237-
return days * ChronoUnit.DAYS.duration().get(chronoUnit);
238-
} else {
237+
return (days * ChronoUnit.DAYS.duration().toMillis()) / chronoUnit.duration().toMillis();
238+
} else {
239239
return chronoUnit.between(comparingDate, value);
240240
}
241241

0 commit comments

Comments
 (0)