-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Microseconds are lost when creating DateTime.parse or DateTime.fromMicrosecondsSinceEpoch #44876
Comments
The web |
Since Flutter Web is probably going mainstream very soon, it would be helpful to devs if the Flutter and Dart teams could collaborate and create an overview list of APIs with different behavior in VM and WEB builds. Since more and many devs new to Dart, will probably start to build cross platforms apps, more devs are likely to stumble on such issues from time to time. It would be good to preempt it a bit at least, and provide a consolidated source for already known such potential pitfalls. Perhaps there already is such an overview in the Dart lang docs site? In that case it would be good to promote it better and reference it from the Flutter site as well. Yes this particular case is of course documented at least in the doc comments for the getter in question, so it is in API docs, IDE tooling and when you drill into the source: But can be easy to miss, especially if you just build something that was originally built just for Flutter VM apps to run on Flutter Web as well. |
On that note, would it be possible to create a lint rule that could be enabled to detect these kind of issues, and it would warn you when you might have an issue due to differences in VM and WEB implementations? |
Assigning to lib to improve the doc on this API to at least say what @lrhn says above. As written, it looks like it could return anything. The implementation uses millisecond precision and multiplies by 1000 here:
A general VM vs Web lint would be difficult ( any API uses |
A lint rule that can catch and warn about certain APIs, that you might stumble on in Flutter Web and VM cross platform dev, would already imo be very useful and helpful, definitely better than nothing and relaying on memory to remember them. Would you like a separate submission of a suggestion/issue for such a lint rule? Just to have it as its own actionable topic instead of the comment I just threw up in the air here to see if it might stick... 😃 |
@rydmike - please do - you can file it here and reference this issue: https://github.com/dart-lang/linter/issues thanks! |
Yes, thank you @rydmike. Issues would be greatly appreciated! |
Added: #58320 |
Apparently, microseconds aren't supported in dart2js: dart-lang/sdk#44876 (comment)
I think I currently have the same issue, here's a quick demo on dartpad. |
By the way, this is only an issue for dart in the Web (e.g. DartPad or Flutter Web). Running your script on other platforms than web would produce expected results. This was ran on macOS:
|
@osaxma Oh nice, thanks ! |
I think this problem is very serious. for example I don't think there is any particular problem when generating with DateTime.now(). I don't think it would be acceptable to have these differences between platforms. I think this problem will cause a very troublesome problem. There are several ideas to work around this problem, but I think these ideas are pretty stupid.
I understand that Dart is a language developed to replace JS. What do you think, guys? |
…f `DataTime`" Original change: https://dart-review.googlesource.com/c/sdk/+/366963 This reverts commit 72b2883. [js_runtime, js_dev_runtime] Implement `microsecond` field of `DataTime` - Move DateTime implementation for dart2js and DDC into a shared place to reduce duplication. - Add a _microsecond field to the web DateTime to track microseconds outside of the JavaScript Date. - The cute dart2js optimization whereby `DateTime.now().millisecondsSinceEpoch` is compiled to `Date.now()` still works. - Both implementations report better errors. - Fixed VM bug with in-range sentinel. Issue: #44876 Issue: firebase/flutterfire#12102 Issue: b/342552853 CoreLibraryReviewExempt: Reapply of unchanged code Change-Id: I7f14b69e412a052ef3fe6b43cc9cf9d96319adb8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368380 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Lasse Nielsen <[email protected]>
As mentioned in the title and as shown in the example below:
Dart SDK on 2.10.4 (example on DartPad)
The text was updated successfully, but these errors were encountered: