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

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

    Issue actions