Wrong calculation for subtracting days for April 1st of 2021 for en_US.
Describe the bug The straightforward calculation yields wrong data. The same case is for Flutter's DateTime class. The culprit is subract days method.
To Reproduce Steps to reproduce the behavior:
- Run the app on en_US locale.
- Make date with Jiffy:
Jiffy([2021, 4, 1]) - subtract 4 days:
Jiffy([2021, 4, 1])..subtract(4) - Observe March 27, not March 28.
Expected behavior Subtracting should yield correct date.
Additional context Looks related with Flutter framework.
I can confirm this issue, not only on en_US but any locale.
Subtract method was giving one day difference on my app calculation for at least 2 months until an angel user pointed it out for me.
What a shame... I've switched to default DateTime calculations, removed everything from jiffy and finally I've run "flutter clean" at least 10 times just to make sure there was no trace of jiffy left on my computer.
I agree. I have filled this Bug to Dart team and they responded to ALWAYS perform add/subtract (modify in general) operations on DateTime object in UTC format, and then convert back.
So all modification operations should look like this:
- convert local to UTC
- perform your operation on UTC date
- convert UTC to local
@MichalDanielDobrzanski Please check your calculation once again? 1st April - 4 days is 28th March. Although I do agree that all date related calculations should be in UTC as recommended by the team, the current state of this project does not involve any bugs and hence there is no need for an update.