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
Compare dates by date portion only #4195
Comments
Set owner to @floitschG. |
This would be useful, but so would the corresponding |
This comment was originally written by thebinarysearcht...@gmail.com Maybe avoid exposing properties and instead have methods that perform comparisons, such as d1.IsAtSameTimeOfDayAs(d2) hah. |
Removed the owner. |
This issue originates from that fact that the modeling of date is incorrect under DateTime, which holds superfluous and wrong information about a date ( if it's only a date). I would say having two additional types ( Date & Time ) would solve this issue. Both could be merged to form a DateTime if needed. final time = Time.now();
final date = Date.today();
final dateTime = DateTime.fromParts(date, time);
final inTenSeconds = time.add(const Duration(seconds: 10));
final tomorrow = Date.tomorrow();
final nextDateTime = DateTime.fromParts(date, inTenSeconds)); // copy with time
final tomorrowDateTime = DateTime.fromParts(tomorrow, time)); // copy with date Those are real world, everyday distinct values, that are in everyday conversations. As such I think those should be part of the sdk. The main issue I have with DateTime representing a date is that it furnish an incorrect api, an user might call The main issue I have with no Time type is that every library that needs it implements their own little class, so you end up mapping from your internal implementation, to flutter, to another impl. Note: Ranges would also be nice. DateRange, TimeRange, DateTimeRange. |
The recommended approach is to represent a plain dates ("calendar date") as a UTC You can still ask a UTC plain date about its hours (it'll be zero). As long as you stay away from local-time |
The "recommended" approach (and only remotely accurate approach that is using DateTime) still suffer from incorrect modeling and incorrect api surface. Ence my proposal of multiple types that more accurately represent reality. The fact that it also solves every issue cited here is also telling. Is there something you do not like about that proposal ? I know most languages I used do not make the distinction, that could be an hint that there is something bad about it. I was thinking maybe serialization but daysSinceEpoch would be as valid as millis, or maybe timezones would break that ? No matter how documented it is, if it's not enforced by the compiler, someone will use the So I'm not a fan of the recommended approach, even if that's what I use. |
This issue was originally filed by thebinarysearc...@gmail.com
There is no easy way to compare the date portion of two dates.
eg. d1.date == d2.date
The text was updated successfully, but these errors were encountered: