Skip to content

Date constructor args should be optional #2582

Closed
@DartBot

Description

@DartBot

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

Activity

kasperl

kasperl commented on Apr 17, 2012

@kasperl

Added Area-Library, Triaged labels.

floitschG

floitschG commented on May 14, 2012

@floitschG
Contributor

Issue #1422 has been merged into this issue.

floitschG

floitschG commented on Jun 20, 2012

@floitschG
Contributor

Fixed some weeks ago.


Added Fixed label.

added a commit that references this issue on Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kasperl@floitschG@DartBot

        Issue actions

          Date constructor args should be optional · Issue #2582 · dart-lang/sdk