Closed Maxim-Mazurok closed 11 months ago
Describe the bug Previously subtracting "P1W" from "P14D" resulted in "P1W" which makes sense. Now it's "P0.651W2DT10H17M45.6S"
To Reproduce You can run this at https://npm.runkit.com/luxon
const { DateTime, Duration } = require("luxon@3.4.0"); const purchaseDate = DateTime.fromObject( { day: 1, month: 1, year: 2020 }, { zone: "UTC" } ); const warranty = Duration.fromObject( { days: 14 }, { conversionAccuracy: "longterm" } ); const now = DateTime.fromObject( { day: 8, month: 1, year: 2020 }, { zone: "UTC" } ); const age = now.diff(purchaseDate).shiftToAll(); const warrantyLeft = warranty.minus(age).shiftToAll(); console.log({ purchaseDate: purchaseDate.toString(), warranty: warranty.toString(), now: now.toString(), age: age.toString(), warrantyLeft: warrantyLeft.toString(), });
it will produce
purchaseDate: "2020-01-01T00:00:00.000Z" warranty: "P14D" now: "2020-01-08T00:00:00.000Z" age: "P1W" warrantyLeft: "P0.651W2DT10H17M45.6S"
Actual vs Expected behavior Running luxon 3.3.0 at https://npm.runkit.com/luxon:
const { DateTime, Duration } = require("luxon@3.3.0"); const purchaseDate = DateTime.fromObject( { day: 1, month: 1, year: 2020 }, { zone: "UTC" } ); const warranty = Duration.fromObject( { days: 14 }, { conversionAccuracy: "longterm" } ); const now = DateTime.fromObject( { day: 8, month: 1, year: 2020 }, { zone: "UTC" } ); const age = now.diff(purchaseDate).shiftToAll(); const warrantyLeft = warranty.minus(age).shiftToAll(); console.log({ purchaseDate: purchaseDate.toString(), warranty: warranty.toString(), now: now.toString(), age: age.toString(), warrantyLeft: warrantyLeft.toString(), });
results in
purchaseDate: "2020-01-01T00:00:00.000Z" warranty: "P14D" now: "2020-01-08T00:00:00.000Z" age: "P1W" warrantyLeft: "P1W"
as expected.
Basically I have 14 days warranty, 7 days age of product, I want to figure out how much warranty left. It should be one week, as it was with luxon 3.3.0
Desktop (please complete the following information):
Thanks. This is likely introduced by https://github.com/moment/luxon/pull/1467. I'll take a look soon.
Fixed in 3.4.1. Thanks for the report
Describe the bug Previously subtracting "P1W" from "P14D" resulted in "P1W" which makes sense. Now it's "P0.651W2DT10H17M45.6S"
To Reproduce You can run this at https://npm.runkit.com/luxon
it will produce
Actual vs Expected behavior Running luxon 3.3.0 at https://npm.runkit.com/luxon:
results in
as expected.
Basically I have 14 days warranty, 7 days age of product, I want to figure out how much warranty left. It should be one week, as it was with luxon 3.3.0
Desktop (please complete the following information):