Skip to content
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

Unexpected results if using microseconds in web #44717

Open
kinex opened this issue Jan 20, 2021 · 2 comments
Open

Unexpected results if using microseconds in web #44717

kinex opened this issue Jan 20, 2021 · 2 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-documentation A request to add or improve documentation

Comments

@kinex
Copy link

kinex commented Jan 20, 2021

Both print statements in this sample code output the same value:

void main() {
  final now = DateTime.now();
  print(now.microsecondsSinceEpoch);
  final later = now.add(Duration(microseconds: 1));
  print(later.microsecondsSinceEpoch);
}

I noticed this while trying my Flutter app in web, because it caused an infinite loop (works fine in mobile). My app is using microseconds extensively for different DateTime calculations, so it seems I have to do a lot of refactoring to make my app compatible with web.

This limitation is indirectly documented here: https://api.dart.dev/stable/2.10.4/dart-core/DateTime/microsecondsSinceEpoch.html

I think this should be documented more clearly at least in DateTime.add and in Duration. Also an analyzer warning would be good.

It is also unclear is it safe to use getter Duration.inMicroseconds in web.

@mraleph mraleph added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Jan 24, 2021
@mraleph
Copy link
Member

mraleph commented Jan 24, 2021

/cc @lrhn

@lrhn lrhn added library-core type-documentation A request to add or improve documentation labels Jan 26, 2021
@jamesderlin
Copy link
Contributor

This would be a limitation of DateTime objects for the web in general and wouldn't specifically be about adding. See #44876.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-documentation A request to add or improve documentation
Projects
None yet
Development

No branches or pull requests

4 participants