-
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
Date constructor should allow arguments to overflow/underflow #2771
Comments
This comment was originally written by @seaneagan Go lang agrees: |
Set owner to @floitschG. |
Issue #1154 has been merged into this issue. |
Issue #445 has been merged into this issue. |
This comment was originally written by domi...@google.com Set owner to domi...@google.com. |
This comment was originally written by dominich@chromium.org |
This comment was originally written by domi...@google.com Added Fixed label. |
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).
The text was updated successfully, but these errors were encountered: