Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration subtraction regression #1482

Closed
Maxim-Mazurok opened this issue Aug 13, 2023 · 2 comments
Closed

Duration subtraction regression #1482

Maxim-Mazurok opened this issue Aug 13, 2023 · 2 comments

Comments

@Maxim-Mazurok
Copy link
Contributor

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):

  • OS: Windows
  • Browser Chrome
  • Luxon version 3.4.0
  • Your timezone Sydney
@icambron
Copy link
Member

Thanks. This is likely introduced by #1467. I'll take a look soon.

@icambron
Copy link
Member

Fixed in 3.4.1. Thanks for the report

brboi added a commit to odoo-dev/odoo that referenced this issue Aug 30, 2023
**Changelog**

**3.4.2 (2023-08-26)**

- Fixes regression from 3.4.1 (moment/luxon#1493)

**3.4.1 (2023-08-23)**

- Fixes for regressions from 3.4.0
  (moment/luxon#1482 and moment/luxon#1488)

**3.4.0 (2023-08-08)**

- Fix type checking on input zones
- Fix Islamic months listing
- Fix normalize() for negative inputs

**3.3.0 (2023-03-03)**

- Fix off-by-one in Interval#count (moment/luxon#1308)
- Support formatting for custom zones (moment/luxon#1377)
- Fix parsing for narrow spaces (moment/luxon#1369)
- Handle leap year issue with AD 100 (moment/luxon#1390)
- Allow parsing of just an offset

**3.2.1 (2023-01-04)**

- Fix for RFC-2822 regex vulnerability
- Better handling of BCP tags with -x- extensions

**3.2.0 (2022-12-29)**

- Allow timeZone to be specified as an intl option
- Fix for diff's handling of end-of-month when crossing leap years
  (moment/luxon#1340)
- Add Interval.toLocaleString() (moment/luxon#1320)

**3.1.1 (2022-11-28)**

- Add Settings.twoDigitCutoffYear

**3.1.0 (2022-10-31)**

- Add Duration.rescale

**3.0.4 (2022-09-24)**

- Fix quarters in diffs (moment/luxon#1279)
- Export package.json in package (moment/luxon#1239)

**3.0.2 (2022-08-28)**

- Lots of doc changes
- Added DateTime.expandFormat
- Added support for custom conversion matrices in Durations
robodoo pushed a commit to odoo/odoo that referenced this issue Sep 4, 2023
**Changelog**

**3.4.2 (2023-08-26)**

- Fixes regression from 3.4.1 (moment/luxon#1493)

**3.4.1 (2023-08-23)**

- Fixes for regressions from 3.4.0
  (moment/luxon#1482 and moment/luxon#1488)

**3.4.0 (2023-08-08)**

- Fix type checking on input zones
- Fix Islamic months listing
- Fix normalize() for negative inputs

**3.3.0 (2023-03-03)**

- Fix off-by-one in Interval#count (moment/luxon#1308)
- Support formatting for custom zones (moment/luxon#1377)
- Fix parsing for narrow spaces (moment/luxon#1369)
- Handle leap year issue with AD 100 (moment/luxon#1390)
- Allow parsing of just an offset

**3.2.1 (2023-01-04)**

- Fix for RFC-2822 regex vulnerability
- Better handling of BCP tags with -x- extensions

**3.2.0 (2022-12-29)**

- Allow timeZone to be specified as an intl option
- Fix for diff's handling of end-of-month when crossing leap years
  (moment/luxon#1340)
- Add Interval.toLocaleString() (moment/luxon#1320)

**3.1.1 (2022-11-28)**

- Add Settings.twoDigitCutoffYear

**3.1.0 (2022-10-31)**

- Add Duration.rescale

**3.0.4 (2022-09-24)**

- Fix quarters in diffs (moment/luxon#1279)
- Export package.json in package (moment/luxon#1239)

**3.0.2 (2022-08-28)**

- Lots of doc changes
- Added DateTime.expandFormat
- Added support for custom conversion matrices in Durations

closes #133599

Related: odoo/enterprise#46556
Signed-off-by: Luca Vitali (luvi) <luvi@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants