Open jamesderlin opened 3 years ago
That's not currently possible.
The DateTime
constructor has optional positional parameters, so it cannot also have a named parameter.
Now, if we allowed both (https://github.com/dart-lang/language/issues/1076), that would probably have been the design all along. If we add that ability, I promise I'll personally put a {bool utc = false}
parameter on the DateTime
constructor.
(My current desired approach is to remove the notion of declaring optional parameters entirely, and make any nullable parameter optional.)
There will be constructor tear-offs.
There are now constructor tear-offs, so that can be used as a work around, meanwhile we eagerly wait for https://github.com/dart-lang/language/issues/1076
It's quite annoying that
DateTime
has separate constructors for non-UTC and UTCDateTime
s instead of offering a single constructor with a boolean flag. This makes attempts to implementcopyWith
-like methods (see https://github.com/dart-lang/sdk/issues/24644) rather tedious and error-prone since they must invoke different constructors based onisUtc
and duplicate all of the arguments.Of course, this wouldn't be a problem if:
(dateTime.isUtc ? DateTime.utc, DateTime.new)(...)
. (Are those coming soon? If so, then this issue is probably moot.)DateTime
provided acopyWith
method (which is https://github.com/dart-lang/sdk/issues/24644).