const class sys::Date

sys::Obj
  sys::Date

@Serializable { simple=true }

Source

Date represents a day in time independent of a timezone.

compare

virtual override Int compare(Obj obj)

Source

Compare based on year, month, and day.

day

Int day()

Source

Get the day of the month as a number between 1 and 31.

dayOfYear

Int dayOfYear()

Source

Return the day of the year as a number between 1 and 365 (or 1 to 366 if a leap year).

defVal

const static Date defVal

Source

Default value is "2000-01-01".

equals

virtual override Bool equals(Obj? that)

Source

Two dates are equal if they have the same year, month, and day.

firstOfMonth

Date firstOfMonth()

Source

Get the first day of this Date's current month.

Example:

Date("2009-10-28").firstOfMonth  =>  2009-10-01
fromIso

static Date? fromIso(Str s, Bool checked := true)

Source

Parse an ISO 8601 date. If invalid format and checked is false return null, otherwise throw ParseErr. The following format is supported:

YYYY-MM-DD

Also see toIso and fromStr.

fromLocale

static Date? fromLocale(Str str, Str pattern, Bool checked := true)

Source

Parse a string into a Date using the given pattern. If string is not a valid format then return null or raise ParseErr based on checked flag. See toLocale for pattern syntax.

fromStr

static new fromStr(Str s, Bool checked := true)

Source

Parse the string into a Date from the programmatic encoding defined by toStr. If the string cannot be parsed into a valid Date and checked is false then return null, otherwise throw ParseErr.

hash

virtual override Int hash()

Source

Return hash of year, month, and day.

isToday

Bool isToday()

Source

Return is this date equal to today.

isTomorrow

Bool isTomorrow()

Source

Return is this date equal to today + 1day.

isYesterday

Bool isYesterday()

Source

Return is this date equal to today - 1day.

lastOfMonth

Date lastOfMonth()

Source

Get the last day of this Date's current month.

Example:

Date("2009-10-28").lastOfMonth  =>  2009-10-31
make

static new make(Int year, Month month, Int day)

Source

Make for the specified date values:

  • year: no restriction (although only 1901-2099 maps to DateTime)
  • month: Month enumeration
  • day: 1-31

Throw ArgErr if any of the parameters are out of range.

midnight

DateTime midnight(TimeZone tz := TimeZone.cur())

Source

Return a DateTime for the beginning of this day at midnight.

minus

@Operator
Date minus(Duration days)

Source

Subtract the specified number of days to this date to get a date in the past. Throw ArgErr if days parameter is not a whole number of days (must be evenly divisible by 24hr).

Example:

Date(2008, Month.feb, 28) - 2day  =>  2008-02-26
minusDate

@Operator
Duration minusDate(Date days)

Source

Return the delta between this and the given date. The result is always an exact multiple of 24 hour days.

Example:

Date(2009, Month.jan, 5) - Date(2009, Month.jan, 2)  =>  3day
month

Month month()

Source

Get the month of this date.

plus

@Operator
Date plus(Duration days)

Source

Add the specified number of days to this date to get a date in the future. Throw ArgErr if days parameter is not a whole number of days (must be evenly divisible by 24hr).

Example:

Date(2008, Month.feb, 28) + 2day  =>  2008-03-01
toCode

Str toCode()

Source

Get this Date as a Fantom expression suitable for code generation.

toDateTime

DateTime toDateTime(Time t, TimeZone tz := TimeZone.cur())

Source

Combine this Date with the given Time to return a DateTime.

toIso

Str toIso()

Source

Format this instance according to ISO 8601 using the pattern:

YYYY-MM-DD

Also see fromIso and toStr.

toLocale

Str toLocale(Str? pattern := null, Locale locale := Locale.cur())

Source

Format this date according to the specified pattern. If pattern is null, then a localized default is used. The pattern format is the same as DateTime.toLocale:

YY     Two digit year             07
YYYY   Four digit year            2007
M      One/two digit month        6, 11
MM     Two digit month            06, 11
MMM    Three letter abbr month    Jun, Nov
MMMM   Full month                 June, November
D      One/two digit day          5, 28
DD     Two digit day              05, 28
DDD    Day with suffix            1st, 2nd, 3rd, 24th
WWW    Three letter abbr weekday  Tue
WWWW   Full weekday               Tuesday
Q      Quarter number             3
QQQ    Quarter with suffix        3rd
QQQQ   Quarter spelled out        3rd Quarter
'xyz'  Literal characters
toStr

virtual override Str toStr()

Source

Return programmatic ISO 8601 string encoding formatted as follows:

YYYY-MM-DD
2009-01-10

Also fromStr, toIso, and toLocale.

today

static Date today(TimeZone tz := TimeZone.cur())

Source

Get today's Date using specified timezone.

tomorrow

static Date tomorrow(TimeZone tz := TimeZone.cur())

Source

Get tomorrow's Date using specified timezone.

weekOfYear

Int weekOfYear(Weekday startOfWeek := Weekday.localeStartOfWeek())

Source

Return the week number of the year as a number between 1 and 53 using the given weekday as the start of the week (defaults to current locale).

weekday

Weekday weekday()

Source

Get the day of the week for this date.

year

Int year()

Source

Get the year as a number such as 2009.

yesterday

static Date yesterday(TimeZone tz := TimeZone.cur())

Source

Get yesterday's Date using specified timezone.