DateFormat constructor

DateFormat([String newPattern, String locale ])

Creates a new DateFormat, using the format specified by newPattern.

For forms that match one of our predefined skeletons, we look up the corresponding pattern in locale (or in the default locale if none is specified) and use the resulting full format string. This is the preferred usage, but if newPattern does not match one of the skeletons, then it is used as a format directly, but will not be adapted to suit the locale.

For example, in an en_US locale, specifying the skeleton

new DateFormat.yMEd();

or the explicit

new DateFormat('EEE, M/d/y');

would produce the same result, a date of the form "Wed, 6/27/2012".

The first version would produce a different format string if used in another locale, but the second format would always be the same.

If locale does not exist in our set of supported locales then an ArgumentError is thrown.

Implementation

DateFormat([String newPattern, String locale]) {
  // TODO(alanknight): It should be possible to specify multiple skeletons eg
  // date, time, timezone all separately. Adding many or named parameters to
  // the constructor seems awkward, especially with the possibility of
  // confusion with the locale. A "fluent" interface with cascading on an
  // instance might work better? A list of patterns is also possible.
  _locale = Intl.verifiedLocale(locale, localeExists);
  addPattern(newPattern);
}