Yesterday, my app suddenly failed. So after hours of debugging, it came down to this.
test("What The Flutter", () {
final a = "2023-03-13T00:00:00.000";
final b = "2023-03-12T00:00:00.000";
final diff = DateTime.parse(a).difference(DateTime.parse(b));
print(diff.inDays);
expect(diff.inDays, 1); // this fails. it says it is 0
});
I suppose it has something to do with something invented in 1895 but not sure and how to write a code to handle this ?
For reference, this passes
test("All Correct after the anomaly day", () {
final a = "2023-03-14T00:00:00.000";
final b = "2023-03-13T00:00:00.000";
final diff = DateTime.parse(a).difference(DateTime.parse(b));
print(diff.inDays);
expect(diff.inDays, 1);
});
Forcing the dates to UTC is not helping
final diff = DateTime.parse(a).toUtc().difference(DateTime.parse(b).toUtc());
This questions is addressing a specific case of dates not behaving as intended, not asking how to find the difference between two dates like this one Flutter: Find the number of days between two dates