Closed Gokulkannan08 closed 11 months ago
You'll need to tell us what time it was when you ran this, and what time zone that was in.
Checked round 10.30 am (IST) in the morning and periodically after that timezone - "Asia/calcutta"
I cannot reproduce this with the following code:
const dummyNow = DateTime.fromISO('2023-08-25T10:30', {zone: 'Asia/Calcutta'}).toMillis();
Settings.now = () => dummyNow;
Settings.defaultZone = 'Asia/Calcutta';
Settings.defaultLocale = 'en-US';
console.log(DateTime.fromISO(new Date('2023-08-07T12:54:56.886Z').toISOString()).toRelative());
This produces "17 days ago" for me, in Node.JS 18, Chrome and Firefox.
Please provide more details for how to reproduce this issue.
I have attached the screenshot below.
Luxon
Moment
Okay, so the date you're using is 2023-08-07T18:24:56
in your time zone. Since the current time in your time zone is 2023-08-27T11:33:00
, 19 days and a few hours have passed. As such the report "19 days ago" is entirely accurate.
Moment.js does some funky rounding when you call fromNow
instead of giving you an accurate report.
In Luxon you can use the padding
option of toRelative
to round up to e.g. the nearest day.
@diesieben07 How to round up with the nearest day using padding
in toRelative()?
const padding = Duration.fromObject({days: 1}).toMillis() / 2;
const relative = DateTime.fromISO('2023-08-07T12:54:56.886Z').toRelative({ padding });
Describe the bug Migrating from moment to luxon: In my case moment.fromNow() and luxon.DateTime.toRelative() return different value
To Reproduce
returns 16 days ago
Actual vs Expected behavior As expected should be 17 days ago
returns 17 days ago