Interface DateStatic

Index

Methods

Methods

public addLocale(code: string, set: Locale): Locale

Adds a locale to the locales understood by Sugar.

method

Date.addLocale(, )

extra

For more see @date_format.

Parameters

  • code: string

    Locale code.

  • set: Locale

    Locale definition.

Returns

Locale

Locale

public create(locale?: string): Date

Alternate Date constructor which understands many different text formats, a timestamp, or another date.

method

Date.create(, [locale] = currentLocale)

extra

If no argument is given, date is assumed to be now. %Date.create% additionally can accept enumerated parameters as with the standard date constructor. [locale] can be passed to specify the locale that the date is in. When unspecified, the current locale (default is English) is assumed. UTC-based dates can be created through the %utc% object. For more see @date_format.

set

Date.utc.create

example

Date.create('July') -> July of this year Date.create('1776') -> 1776 Date.create('today') -> today Date.create('wednesday') -> This wednesday Date.create('next friday') -> Next friday Date.create('July 4, 1776') -> July 4, 1776 Date.create(-446806800000) -> November 5, 1955 Date.create(1776, 6, 4) -> July 4, 1776 Date.create('1776?07?04?', 'ja') -> July 4, 1776 Date.utc.create('July 4, 1776', 'en') -> July 4, 1776

Parameters

  • locale?: string optional

    Locale to create the date in, default = currentLocale.

Returns

Date

Date

public create(d: string, locale?: string): Date

see

create

Parameters

  • d: string

    Human readable date to convert to a Date object.

  • locale?: string optional

Returns

Date

public create(year: number, month: number, day: number, locale?: string): Date

see

create

Parameters

  • year: number

    Year YYYY

  • month: number

    Month MM

  • day: number

    Day DD

  • locale?: string optional

Returns

Date

public future(d: string, locale?: string): Date

Alternate form of %Date.create% with any ambiguity assumed to be the future.

method

Date.future(, [locale] = currentLocale)

extra

For example %"Sunday"% can be either "the Sunday coming up" or "the Sunday last" depending on context. Note that dates explicitly in the past ("last Sunday") will remain in the past. This method simply provides a hint when ambiguity exists. UTC -based dates can be created through the %utc% object. For more, see @date_format.

set

Date.utc.future

example

Date.future('July') -> July of this year or next depending on the current month Date.future('Wednesday') -> This wednesday or next depending on the current weekday

Parameters

  • d: string

    Future human redable date to convert to a Date object.

  • locale?: string optional

    Locale to create the date in, default = currentLocale.

Returns

Date

Date

public getLocale(code?: string): Locale

Gets the locale for the given code, or the current locale.

method

Date.getLocale([code] = current)

extra

The resulting locale object can be manipulated to provide more control over date localizations. For more about locales, see @date_format.

Parameters

  • code?: string optional

    Locale code to retrieve.

Returns

Locale

Locale

public now(): string

Returns the number of milliseconds since January 1st, 1970 00:00:00 (UTC time).

method

Date.now()

extra

Provided for browsers that do not support this method.

example

Date.now() -> ex. 1311938296231

Returns

string

String

public past(d: string, local?: string): Date

Alternate form of %Date.create% with any ambiguity assumed to be the past.

method

Date.past(, [locale] = currentLocale)

extra

For example %"Sunday"% can be either "the Sunday coming up" or "the Sunday last" depending on context. Note that dates explicitly in the future ("next Sunday") will remain in the future. This method simply provides a hint when ambiguity exists. UTC-based dates can be created through the %utc% object. For more, see @date_format.

set

Date.utc.past

example

Date.past('July') -> July of this year or last depending on the current month Date.past('Wednesday') -> This wednesday or last depending on the current weekday

Parameters

  • d: string

    Past human readable date to convert to a Date object.

  • local?: string optional

Returns

Date

Date

public range(start: Date, end: Date): DateRange

Creates a new date range.

method

Date.range([start], [end])

extra

If either [start] or [end] are null, they will default to the current date.

Parameters

  • start: Date

    Beginning date.

  • end: Date

    Ending date.

Returns

DateRange

DateRange

public setLocale(code: string): Locale

Sets the current locale to be used with dates.

method

Date.setLocale()

extra

Sugar has support for 13 locales that are available through the "Date Locales" package. In addition you can define a new locale with %Date.addLocale%. For more see @date_format.

Parameters

  • code: string

    Locale code.

Returns

Locale

Locale