-
Notifications
You must be signed in to change notification settings - Fork 123
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
Incorrect behaviour of add method when traversing a date in which daylight saving time transition occurs #81
Comments
I'm having the exact problem when subtracting weeks. Input: |
I believe Jiffy has nothing to do with this. I solved it by using
|
In fact, what @anisalibegic found is correct: the bug is in Dart SDK itself. I've replicated this with this Dart code: //let's start with a date before the DST transition
DateTime dt = DateTime(2020, 10, 25, 16, 10, 00, 999);
print(dt);
//and let's go to the start of week. this code is the same used by Jiffy
DateTime newDate = dt.subtract(Duration(days: dt.weekday - 1));
DateTime dt2 = DateTime(newDate.year, newDate.month, newDate.day);
print(dt2);
//then, let's add a week. again, I'm using the same code that Jiffy uses
dt2 = dt2.add(Duration(days: 7));
print(dt2); In my timezone, this is going to be 2020-10-25 23:00:00.000, but that's wrong, because I would expect it to go to the end of the day, so to 2020-10-26 00:00:00.000. If we try to change the starting date, assuming it to be, for example, 2020-11-25, we will get a correct behaviour. I'll try to search in Dart repository to see if there already is any related issue. Otherwise, I'll open one. |
I've just opened an issue on Dart's SDK repository: dart-lang/sdk#44014 |
Jiffy would work correctly (ignoring DST changes) when adding days or weeks if its implementation had special code for it, the way it has special code for adding months and years. It is up to the Jiffy package maintainers if they want to change adding days and weeks to work this way. It is also solved by using UTC times when working with calendar days, since a calendar day has no time of day associated with it and is independent of time zones. |
I am from Android developer. |
I made a class in my project only for date calculation. This class is wrapping Jiffy. You can modify and use it if need.
|
@whesse I agree, Jiffy could do its own implementation to correct this, maybe within the subtract and add function we could add utc implementation to manipulate the date and later return its local time. A similar approach to @wonpyohong solution |
This is expected behaviour since jiffy's https://api.flutter.dev/flutter/dart-core/DateTime/add.html
This should either be better documented in jiffy's
|
Hi,
I have recently stumbled over this problem. My current timezone is 'Europe/Rome', where DST switches off the last Sunday of October. If I execute
due to the DST transition, the result is not
2020-10-26 00:00:00
, as I would expect, but2020-10-25 23:00:00
. This breaks all the rest of my computation.I think the behavior of Jiffy is incorrect. Adding a week should return
2020-10-26 00:00:00
, independently from the actual number of hours of difference. As a comparison, the momentjs library withcorrectly returns
Moment<2020-10-26T00:00:00+01:00>
.This is not the only instance of this problem. For example,
returns again
2020-10-25 23:00:00
instead of ``2020-10-26 00:00:00```.The text was updated successfully, but these errors were encountered: