LocalDate
Type
The LocalDate
type represents a date with the ISO-8601 calendar standard which uses theyyyy-mm-dd
format. That is,
it has a year
, month
and day
field. Unlike DateTime
, it does not have timezone information or more granular time
units.
A LocalDate
value can be constructed using localDateOf.
Methods
day
<function> Gets the day-of-month.
Receiver
LocalDate
Returns
Number - day-of-month (1-31)
Usage
localDateOf(2021, 02, 08).day() == 8
month
<function> Gets the month-of-year.
Receiver
LocalDate
Returns
Number - month-of-year (1-12)
Usage
localDateOf(2021, 02, 08).month() == 2
year
<function> Gets the year.
Receiver
LocalDate
Returns
Number - the year (e.g., 1999)
Usage
localDateOf(2021, 02, 08).year() == 2021
firstDayOfYear
<function> Returns a LocalDate value with the date set to the first day of the year.
Receiver
LocalDate
Returns
LocalDate - a LocalDate value with the date set to the first day of the year
Usage
localDateOf(2021, 02, 08).firstDayOfYear() == localDateOf(2021, 01, 01)
lastDayOfYear
<function> Returns a LocalDate value with the date set to the last day of the year.
Receiver
LocalDate
Returns
LocalDate - a LocalDate value with the date set to the first day of the year
Usage
localDateOf(2021, 02, 08).lastDayOfYear() == localDateOf(2021, 12, 31)
firstDayOfMonth
<function> Returns a LocalDate value with the date set to the first day of the month.
Receiver
LocalDate
Returns
LocalDate - a LocalDate value with the date set to the first day of the month
Usage
localDateOf(2021, 02, 08).firstDayOfMonth() == localDateOf(2021, 02, 01)
lastDayOfMonth
<function> Returns a LocalDate value with the date set to the last day of the month.
Receiver
LocalDate
Returns
LocalDate - a LocalDate value with the date set to the last day of the month
Usage
localDateOf(2021, 02, 08).lastDayOfMonth() == localDateOf(2021, 02, 28)
localDateOf(2020, 02, 13).lastDayOfMonth() == localDateOf(2020, 02, 29)
isAfter
<function> Determine whether this LocalDate is after another LocalDate (or equal if inclusive is true).
Receiver
LocalDate
Arguments
date - LocalDate - other LocalDate to compare against
inclusive - Boolean - return true if both are at the same point in time
Returns
Boolean - whether this date is after the provided date
Usage
localDateOf(2021, 02, 08).isAfter(localDateOf(1970, 01, 01), false) == true
localDateOf(1970, 01, 01).isAfter(localDateOf(2021, 02, 08), false) == false
localDateOf(1970, 01, 01).isAfter(localDateOf(1970, 01, 01), true) == true
isBefore
<function> Determine whether this LocalDate is before another LocalDate (or equal if inclusive is true).
Receiver
LocalDate
Arguments
date - LocalDate - other LocalDate to compare against
inclusive - Boolean - return true if both are at the same point in time
Returns
Boolean - whether this date is before the provided date
Usage
localDateOf(2021, 02, 08).isBefore(localDateOf(1970, 01, 01), false) == false
localDateOf(1970, 01, 01).isBefore(localDateOf(2021, 02, 08), false) == true
localDateOf(1970, 01, 01).isBefore(localDateOf(1970, 01, 01), true) == true
isBetween
<function> Determine whether this LocalDate falls within the range of a lower and upper bound (or equal to either if inclusive is true).
Receiver
LocalDate
Arguments
low - LocalDate - lower bound of the range
high - LocalDate - upper bound of the range
inclusive - Boolean - return true if equal to either
Returns
Boolean - whether this date is before the provided date
Usage
localDateOf(1970, 01, 01).isBetween(localDateOf(1789, 07, 14), localDateOf(2021, 02, 08), false) == true
localDateOf(1789, 07, 14).isBetween(localDateOf(1970, 01, 01), localDateOf(2021, 02, 08), false) == false
localDateOf(1970, 01, 01).isBetween(localDateOf(1970, 01, 01), localDateOf(1970, 01, 01), true) == true
periodUntil
<function> Returns the Period until another LocalDate. The result will be negative if the other date is in the past.
Receiver
LocalDate
Arguments
date - LocalDate - other DateTime to compare against
Returns
Period - period until the provided other DateTime
Usage
localDateOf(2021, 01, 08).periodUntil(localDateOf(2021, 02, 08)) == months(1)
localDateOf(2021, 02, 05).periodUntil(localDateOf(2021, 02, 08)) == days(3)
localDateOf(2021, 02, 08).periodUntil(localDateOf(2021, 02, 05)) == days(-3)
plus
<function> Returns a date with the Period added to it.
Receiver
LocalDate
Arguments
delta - Period - the Period to add
Returns
LocalDate - a date with the Period added to it
Usage
localDateOf(2021, 02, 05).plus(days(3)) == localDateOf(2021, 02, 08)
localDateOf(2021, 02, 05) + days(3) == localDateOf(2021, 02, 08)
minus
<function> Returns a date with the Period subtracted from it.
Receiver
LocalDate
Arguments
delta - Period - the Period to subtract
Returns
LocalDate - a date with the Period subtracted from it
Usage
localDateOf(2021, 02, 08).minus(days(3)) == localDateOf(2021, 02, 05)
localDateOf(2021, 02, 08) - days(3) == localDateOf(2021, 02, 05)
atStartOfDay
<function> Returns a DateTime value that corresponds to start of day of the LocalDate in question in the given time zone.
Receiver
LocalDate
Arguments
zoneId - Text - the time zone
Returns
DateTime - a DateTime value that corresponds to start of the day in the given time zone
Usage
localDateOf(2021, 02, 08).atStartOfDay("Z") == 2021-02-08T00:00:00Z
dayOfWeek
<function> Returns the day-of-week of the LocalDate in question (e.g., Monday).
Receiver
LocalDate
Returns
DayOfWeek - a DayOfWeek value that corresponds to the day-of-week
Usage
localDateOf(2021, 02, 08).dayOfWeek() == DayOfWeek.Monday