-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
All DateTimes must be in UTC! #22
Comments
The reason for this limitation is that Dart's date/time handling is very limited, and If you're working with final localDateTime = DateTime.now();
final dateTimeForRrule = DateTime.utc(
localDateTime.year,
localDateTime.month,
localDateTime.day,
localDateTime.hour,
localDateTime.minute,
localDateTime.second,
localDateTime.millisecond,
localDateTime.microsecond,
); |
Thanks - that is what I ended up doing, and it worked fine for now. I have to fake UTC and reverse as well, because the result is not true UTC. My concern was maintenance since, like you said, a developer could try to convert utc/local with DateTime _fakeUTC(DateTime nonUtc) {
return DateTime.utc(nonUtc.year, nonUtc.month, nonUtc.day, nonUtc.hour,
nonUtc.minute, nonUtc.second, nonUtc.millisecond, nonUtc.microsecond);
}
DateTime _reverseFakeUTC(DateTime fakeUtc) {
return DateTime(
fakeUtc.year,
fakeUtc.month,
fakeUtc.day,
fakeUtc.hour,
fakeUtc.minute,
fakeUtc.second,
fakeUtc.millisecond,
fakeUtc.microsecond);
} The problem of using UTC is that when retrieving the instances, any timezone specific conditions is lost. If you retrieve an instance post a change in daylight savings, it would not be reflected accordingly. |
The current recipe (i.e. This package is great, and I think this is the most important missing feature, handling local DateTimes directly. There are ways to handle the intricacies of local timezones, such as flutter's If you think that it's not worth the trouble, I would at least include the conversion to and from UTC in the package itself, so that users don't have to worry about which is the correct way of converting their local datetimes to a fake UTC datetime and back. In any case, thanks for this package! |
I thought about this problem some more and want to offer a different solution: A separate class called, e.g., That class would be inspired by the no longer maintained time_machine package (a port of .NET's Noda Time) and JavaScript's Temporal proposal and its API could look like the following: @immutable
class LocalDateTime implements Comparable<LocalDateTime> {
/// Creates an instance based on [dateTime]'s year, day, hour, etc.
///
/// This ignores `dateTime.millisecondsSinceEpoch` and `dateTime.isUtc`.
LocalDateTime.fromDateTime(DateTime dateTime);
static LocalDateTime get now => LocalDateTime.fromDateTime(DateTime.now());
// This class will store the year, month, day, hour, minute, second, and
// millisecond using helper classes like `LocalDate` and `LocalTime`.
/// Returns a new [DateTime] with the same year, day, hour, etc. and `isUtc == true`.
DateTime get dateTimeInUtc;
/// Returns a new [DateTime] with the same year, day, hour, etc. and `isUtc == false`.
DateTime get dateTimeInLocalZone;
} These classes would also have more utilities like Since these classes are useful outside recurrence rules as well (e.g., in my Flutter package timetable, I could also make good use of What do you think about this proposal? |
I think that could be a good long-term solution. I would call it something different than
I didn't know about the |
@plammens Valid point, I think I'll call these classes Actually, both rrule and timetable once used time_machine, but, due to bugs and lacking maintenance of that package, users requested a change away from time_machine: JonasWanke/timetable#33, #16, and #9. Both packages now use Dart's native |
I'm slightly confused as to why "all DateTimes must be in UTC".
Requirement: I want a recurrence every business day of the week (MON-FRI) at 23:59:59 in local time .
Scenario: Let's say user is on UTC-4 and wants a recurrence every day of the week MON-FRI at 23:59:59 in local time. If we convert FRI 23:59:59 to UTC, we now have SAT 03:59:59 which breaks my requirement of every business day of the week. So in the end, when retrieving the instances, I would only have a total of 4 instances since the 5th instance (Friday) is actually on Saturday_UTC, but Friday_Local.
I guess is this a new requirement? To support local recurrence, or is there any other way to deal with that? I am not sure if anyone would care about days of the week in UTC time, since business days/weekends are always relevant in local time.
Obviously I could fake my local time to be UTC, but that would be wrong by definition, and it would only be to retrieve instances.
The text was updated successfully, but these errors were encountered: