Skip to content

//core/io.islandtime/Date

Date

@Serializable(with = DateIsoSerializer::class)

class Date(val year: Int, val month: Month, day: Int) : Comparable<Date>

A date in an ambiguous region.

Parameters

common

year the year
month the month
day the day of the month

Throws

DateTimeException if the year or day is invalid

Constructors

Date

common

constructor(year: Int, monthNumber: Int, day: Int)

Creates a Date from a year, ISO month number, and day of month.

constructor(year: Int, month: Month, day: Int)

Creates a Date from a year, month, and day of month.

Types

Name Summary
Companion

common


object Companion

Properties

Name Summary
dayOfMonth

common


val dayOfMonth: Int

The day of the month.
dayOfUnixEpoch

common


val dayOfUnixEpoch: Long

The day of the Unix epoch.
dayOfWeek

common


val dayOfWeek: DayOfWeek

The day of the week.
dayOfYear

common


val dayOfYear: Int

The day of the year.
daysSinceUnixEpoch

common


val daysSinceUnixEpoch: Days

The number of days away from the Unix epoch (1970-01-01T00:00Z) that this date falls.
endOfDay

common


val Date.endOfDay: DateTime

The DateTime at the last representable instant of the day. Daylight savings transitions are not taken into account, so the returned date-time may not necessarily exist in all time zones.
endOfMonth

common


val Date.endOfMonth: Date

The date at the end of the month that this date falls in.
endOfWeek

common


val Date.endOfWeek: Date

The date at the end of the ISO week that this date falls in.
endOfYear

common


val Date.endOfYear: Date

The date at the end of the year that this date falls in.
isInLeapYear

common


val Date.isInLeapYear: Boolean

Checks if this date falls within a leap year.
isLeapDay

common


val Date.isLeapDay: Boolean

Checks if this date is February 29.
lengthOfMonth

common


val Date.lengthOfMonth: Days

The length of this date's month in days.
lengthOfWeekBasedYear

common


val Date.lengthOfWeekBasedYear: Weeks

The length of the ISO week-based year that this date falls in, either 52 or 53 weeks.
lengthOfYear

common


val Date.lengthOfYear: Days

The length of this date's year in days.
month

common


val month: Month

The month of the year.
monthNumber

common


val monthNumber: Int

The ISO month number, from 1-12.
startOfDay

common


val Date.startOfDay: DateTime

The DateTime at the start of the day. Daylight savings transitions are not taken into account, so the returned date-time may not necessarily exist in all time zones.
startOfMonth

common


val Date.startOfMonth: Date

The date at the start of the month that this date falls in.
startOfWeek

common


val Date.startOfWeek: Date

The date at the start of the ISO week that this date falls in.
startOfYear

common


val Date.startOfYear: Date

The date at the start of the year that this date falls in.
week

common


val Date.week: DateRange

The range defining the ISO week that this date falls within.
weekBasedYear

common


val Date.weekBasedYear: Int

The week-based year used in the ISO week date system. This value differs from the regular ISO year when the week number falls in the preceding or following year.
weekOfMonth

common


val Date.weekOfMonth: Int

The week of the month, from 0-6, calculated using the ISO week definition.
weekOfWeekBasedYear

common


val Date.weekOfWeekBasedYear: Int

The week number used in the ISO week date system.
weekOfYear

common


val Date.weekOfYear: Int

The week of the year, calculated using the ISO week definition. If the week number is associated with the preceding year, 0 will be returned.
year

common


val year: Int

The year.

Functions

Name Summary
at

common


infix fun Date.at(offsetTime: OffsetTime): OffsetDateTime

Combines a local date with a time and UTC offset to create an OffsetDateTime.

common


infix fun Date.at(time: Time): DateTime

Combines a Date with a Time to create a DateTime.
atTime

common


fun Date.atTime(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0): DateTime

Combines a Date with a time to create a DateTime.
compareTo

common


open operator override fun compareTo(other: Date): Int
component1

common


operator fun component1(): Int
component2

common


operator fun component2(): Month
component3

common


operator fun component3(): Int
copy

common


fun copy(year: Int = this.year, dayOfYear: Int): Date

fun copy(year: Int = this.year, month: Month = this.month, dayOfMonth: Int = this.day): Date

fun copy(year: Int = this.year, monthNumber: Int, dayOfMonth: Int = this.day): Date

Returns a copy of this date with the values of any individual components replaced by the new values specified.
downTo

common


infix fun Date.downTo(to: Date): DateDayProgression

Creates a progression of dates in descending order.
endOfDayAt

common


fun Date.endOfDayAt(zone: TimeZone): ZonedDateTime

The ZonedDateTime at the last representable instant of the day in zone, taking into account any daylight savings transitions.
endOfWeek

common


fun Date.endOfWeek(settings: WeekSettings): Date

The date at the end of the week that this date falls in. The first day of the week will be determined by settings. The first day of the week will be determined by the system settings. The first day of the week will be determined by the system settings. This may differ from the first day of the week associated with the default locale on platforms that allow this to be customized.

common


fun Date.endOfWeek(locale: Locale): Date

The date at the end of the week that this date falls in. The first day of the week will be determined by locale.
equals

common


open operator override fun equals(other: Any?): Boolean
hashCode

common


open override fun hashCode(): Int
minus

common


operator fun minus(centuries: Centuries): Date

Returns this date with centuries subtracted from it.

common


operator fun minus(days: Days): Date

Returns this date with days subtracted from it.

common


operator fun minus(decades: Decades): Date

Returns this date with decades subtracted from it.

common


operator fun minus(months: Months): Date

Returns this date with months subtracted from it.

common


operator fun minus(period: Period): Date

Returns this date with period subtracted from it.

common


operator fun minus(weeks: Weeks): Date

Returns this date with weeks subtracted from it.

common


operator fun minus(years: Years): Date

Returns this date with years subtracted from it.
next

common


fun Date.next(dayOfWeek: DayOfWeek): Date

The next date after this one that falls on dayOfWeek.
nextOrSame

common


fun Date.nextOrSame(dayOfWeek: DayOfWeek): Date

The next date that falls on dayOfWeek, or this date if it falls on the same day.
plus

common


operator fun plus(centuries: Centuries): Date

Returns this date with centuries added to it.

common


operator fun plus(days: Days): Date

Returns this date with days added to it.

common


operator fun plus(decades: Decades): Date

Returns this date with decades added to it.

common


operator fun plus(months: Months): Date

Returns this date with months added to it.

common


operator fun plus(period: Period): Date

Returns this date with period added to it.

common


operator fun plus(weeks: Weeks): Date

Returns this date with weeks added to it.

common


operator fun plus(years: Years): Date

Returns this date with years added to it.
previous

common


fun Date.previous(dayOfWeek: DayOfWeek): Date

The last date before this one that falls on dayOfWeek.
previousOrSame

common


fun Date.previousOrSame(dayOfWeek: DayOfWeek): Date

The previous date that falls on dayOfWeek, or this date if it falls on the same day.
rangeTo

common


operator fun rangeTo(other: Date): DateRange
startOfDayAt

common


fun Date.startOfDayAt(zone: TimeZone): ZonedDateTime

The ZonedDateTime at the start of the day in zone, taking into account any daylight savings transitions.
startOfWeek

common


fun Date.startOfWeek(settings: WeekSettings): Date

The date at the start of the week that this date falls in. The first day of the week will be determined by settings.

common


fun Date.startOfWeek(locale: Locale): Date

The date at the start of the week that this date falls in. The first day of the week will be determined by locale.
toJavaLocalDate

jvm


fun Date.toJavaLocalDate(): LocalDate

Converts this date to an equivalent Java LocalDate.
toNSDateComponents

darwin


fun Date.toNSDateComponents(includeCalendar: Boolean = false): <Error class: unknown class>

Converts this date to an equivalent NSDateComponents object.
toString

common


open override fun toString(): String

Converts this date to a string in ISO-8601 extended format using the "calendar date" form. For example, 2012-04-15.
toWeekDate

common


inline fun <T> Date.toWeekDate(action: (year: Int, week: Int, day: Int) -> T): T

Converts this date to an ISO week date representation.

common


inline fun <T> Date.toWeekDate(settings: WeekSettings, action: (year: Int, week: Int, day: Int) -> T): T

Converts this date to a week date representation using the week definition in settings.

common


inline fun <T> Date.toWeekDate(locale: Locale, action: (year: Int, week: Int, day: Int) -> T): T

Converts this date to a week date representation using the week definition associated with the provided locale.
toYear

common


fun Date.toYear(): Year

Returns this date with the precision reduced to the year.
toYearMonth

common


fun Date.toYearMonth(): YearMonth

Returns this date with the precision reduced to the month.
until

common


infix fun Date.until(to: Date): DateRange

Creates a DateRange containing all the days from this date up to, but not including to.
week

common


fun Date.week(settings: WeekSettings): DateRange

The range defining the week that this date falls within. The first day of the week will be determined by the provided settings.

common


fun Date.week(locale: Locale): DateRange

The range defining the week that this date falls within. The first day of the week will be the default associated with the provided locale.
weekBasedYear

common


fun Date.weekBasedYear(settings: WeekSettings): Int

The week-based year, calculated using the week definition in settings. This value differs from the regular ISO year when the week number falls in the preceding or following year.

common


fun Date.weekBasedYear(locale: Locale): Int

The week-based year, calculated using the week definition associated with the provided locale. This value differs from the regular ISO year when the week number falls in the preceding or following year.
weekOfMonth

common


fun Date.weekOfMonth(settings: WeekSettings): Int

The week of the month, from 0-6, calculated using the week definition in settings.

common


fun Date.weekOfMonth(locale: Locale): Int

The week of the month, from 0-6, calculated using the default week definition associated with the provided locale.
weekOfWeekBasedYear

common


fun Date.weekOfWeekBasedYear(settings: WeekSettings): Int

The week number of the week-based year, calculated using the week definition in settings.

common


fun Date.weekOfWeekBasedYear(locale: Locale): Int

The week number of the week-based year, calculated using the week definition associated with the provided locale.
weekOfYear

common


fun Date.weekOfYear(settings: WeekSettings): Int

The week of the year, calculated using the week definition in settings. If the week number is associated with the preceding year, 0 will be returned.

common


fun Date.weekOfYear(locale: Locale): Int

The week of the year, calculated using the week definition associated with the provided locale. If the week number is associated with the preceding year, 0 will be returned.