Skip to content

Date constructor args should be optional #2582

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

Closed
DartBot opened this issue Apr 16, 2012 · 3 comments
Closed

Date constructor args should be optional #2582

DartBot opened this issue Apr 16, 2012 · 3 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 16, 2012

This issue was originally filed by @seaneagan


Many date libraries provide constructors with optional arguments for each date part beyond the year, each defaulting to the smallest possible amount. In Dart this could look like:

Date(
  int year, [
  int month = 1,
  int day = 1,
  int hour = 0,
  int minute = 0,
  int second = 0,
  int millisecond = 0,
  this.timeZone = TimeZone.LOCAL]); // see issue #2581

This also removes the need for Date.withTimeZone

Examples:

Date now = new Date.now();

Date startOfDay = new Date(now.year, now.month, now.day);
Date eightOClock = new Date(now.year, now.month, now.day, 8);
Date endOfDay = new Date(now.year, now.month, now.day + 1);
Date startOfMonth = new Date(now.year, now.month);
Date ides = new Date(now.year, now.month, 15);
Date endOfMonth = new Date(now.year, now.month + 1);
Date startOfYear = new Date(now.year);
Date middleOfYear = new Date(now.year, Date.JUL);
Date endOfYear = new Date(now.year + 1);

See:

only year required:

http://www.ruby-doc.org/core-1.9.3/Time.html
http://momentjs.com/docs/#/parsing/javascript-array/

year, month, and day required (less useful):

http://docs.python.org/library/datetime.html#datetime-objects
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

@kasperl
Copy link

kasperl commented Apr 17, 2012

Added Area-Library, Triaged labels.

@floitschG
Copy link
Contributor

Issue #1422 has been merged into this issue.

@floitschG
Copy link
Contributor

Fixed some weeks ago.


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 Jun 20, 2012
dart-bot pushed a commit that referenced this issue Aug 11, 2020
> git log --oneline 04b054b62cc437cf23451785fdc50e49cd9de139..master
0d185a39 (HEAD -> master, origin/master, origin/HEAD) Push null-safety forwards to 2.11 (#2604)
56f9f27f Hide outdated --mode flag (#2603)
61ce6f81 Avoid double loop (#2605)
fa6e57d7 (disable_mixed_mode_validation) Fix outdated latest ordering (#2598)
6549e4aa Remove unused dependency from pubspec.yaml (#2592)
61543d07 Don't look for external package foo during testing (#2599)
590b448f Fixed license headers (#2595)
04e0601e Don't show entries for dev-dependencies in outdated --json --no-dev-dependencies (#2591)
8c3778c4 Configure GitHub move app (#2578)
eec7beca (top_level_command) Pass --(no-)sound-null-safety arg through to VM. (#2542)
152e4740 Warn about publishing in mixed mode (#2583)
0b7a3abe Removed april fools toys (#2325)
b74a5b73 Actually print hints (#2582)
8ec3a66d (pub2) Fix outdated --no-color (#2572)
7bb3d4e6 Use getSdkPath() in NullSafetyAnalysis (#2573)
3c578f24 Drop the "magic" package concept (#2577)
0e967ff0 Remove unused function (#2570)
988fefef Remove dependency overrides (#2568)

Change-Id: I58bf14234ed55bf9d825de60a40ded1d65281195
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158003
Reviewed-by: Jonas Jensen <[email protected]>
Commit-Queue: Sigurd Meldgaard <[email protected]>
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