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

Date constructor should allow arguments to overflow/underflow #2771

Closed
DartBot opened this issue Apr 27, 2012 · 8 comments
Closed

Date constructor should allow arguments to overflow/underflow #2771

DartBot opened this issue Apr 27, 2012 · 8 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.

Comments

@DartBot
Copy link

DartBot commented Apr 27, 2012

This issue was originally filed by @seaneagan


In JavaScript, the Date constructor allows the individual parts to overflow and underflow. This facilitates calendar based date addition and subtraction, and other relative date manipulation, for example:

final now = new Date.now();

// "end of" dates
final endOfDay = new Date(now.year, now.month, now.day + 1, 0, 0, 0, 0);
final endOfMonth = new Date(now.year, now.month + 1, 0, 0, 0, 0);

// date addition, including DST transitions
final inNinetyDays = new Date(now.year, now.month, now.day + 90, now.hours, now.minutes, now.seconds, now.milliseconds);
final sixMonthsAgo = new Date(now.year, now.month - 6, now.day, now.hours, now.minutes, now.seconds, now.milliseconds);

The dart2js version of Date supports this, since it just compiles to using the native JavaScript Date constructor. The VM version though currently does not allow this, it adds checks that each part is within bounds (1 - 12 for month, 1 - 31 for day, 0 - 23 for hour, 0 - 59 for minute and second, 0 - 999 for millisecond).

@DartBot
Copy link
Author

DartBot commented Apr 27, 2012

This comment was originally written by @seaneagan


Go lang agrees:

http://golang.org/pkg/time/#Date

@dgrove
Copy link
Contributor

dgrove commented Apr 27, 2012

Added Area-VM, Triaged labels.

@ghost
Copy link

ghost commented Apr 27, 2012

Set owner to @floitschG.
Removed Area-VM label.
Added Area-Library label.

@floitschG
Copy link
Contributor

Issue #1154 has been merged into this issue.

@floitschG
Copy link
Contributor

Issue #445 has been merged into this issue.

@DartBot
Copy link
Author

DartBot commented Aug 2, 2012

This comment was originally written by domi...@google.com


Set owner to domi...@google.com.
Added Started label.

@DartBot
Copy link
Author

DartBot commented Aug 6, 2012

This comment was originally written by dominich@chromium.org


https://chromiumcodereview.appspot.com/10832166

@DartBot
Copy link
Author

DartBot commented Aug 31, 2012

This comment was originally written by domi...@google.com


Added Fixed label.

@DartBot DartBot added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Aug 31, 2012
This issue was closed.
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.
Projects
None yet
Development

No branches or pull requests

3 participants