Skip to content

//core/io.islandtime/YearMonth

YearMonth

common

class YearMonth(year: Int, month: Month) : Comparable<YearMonth>

A month in a particular year.

Parameters

common

year the year
month the month of the year

Throws

io.islandtime.DateTimeException if the year is outside the supported range

Constructors

YearMonth

common

fun YearMonth(year: Int, monthNumber: Int)

Creates a YearMonth.
YearMonth

common

fun YearMonth(year: Int, month: Month)

Creates a YearMonth.

Types

Name Summary
Companion

common


object Companion

Functions

Name Summary
compareTo

common


open operator override fun compareTo(other: YearMonth): Int
contains

common


operator fun contains(date: Date): Boolean

Checks if this year contains the specified date.
copy

common


fun copy(year: Int = this.year, month: Month = this.month): YearMonth

fun copy(year: Int = this.year, monthNumber: Int): YearMonth

Returns a copy of this year-month with the values of any individual components replaced by the new values specified.
equals

common


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

common


open override fun hashCode(): Int
minus

common


operator fun minus(centuries: Centuries): YearMonth

Returns this year-month with centuries subtracted from it.

common


operator fun minus(decades: Decades): YearMonth

Returns this year-month with decades subtracted from it.

common


operator fun minus(months: Months): YearMonth

Returns this year-month with months subtracted from it.

common


operator fun minus(years: Years): YearMonth

Returns this year-month with years subtracted from it.
plus

common


operator fun plus(centuries: Centuries): YearMonth

Returns this year-month with centuries added to it.

common


operator fun plus(decades: Decades): YearMonth

Returns this year-month with decades added to it.

common


operator fun plus(months: Months): YearMonth

Returns this year-month with months added to it.

common


operator fun plus(years: Years): YearMonth

Returns this year-month with years added to it.
toString

common


open override fun toString(): String

Converts this date-time to a string in ISO-8601 extended format. For example, 2012-04.

Properties

Name Summary
dateRange

common

val dateRange: DateRange

The range of dates within this year-month.
dayRange

common

val dayRange: IntRange

The range of days within this year-month.
endDate

common

val endDate: Date

The Date representing the last day in this year-month.
firstDayOfYear

common

val firstDayOfYear: Int

The ordinal date corresponding to the first day of this year-month.
isInLeapYear

common

val isInLeapYear: Boolean

Checks if this year-month falls within a leap year.
lastDay

common

val lastDay: Int

The last day of the year-month.
lastDayOfYear

common

val lastDayOfYear: Int

The ordinal date corresponding to the last day of this year-month.
lengthOfMonth

common

val lengthOfMonth: Days

The length of the year-month in days.
lengthOfYear

common

val lengthOfYear: Days

The length of the 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.
startDate

common

val startDate: Date

The Date representing the first day in this year-month.
year

common

val year: Int

The year.

Extensions

Name Summary
atDay

common


fun YearMonth.atDay(day: Int): Date

Combines a YearMonth with a day of the month to create a Date.
toJavaYearMonth

jvm


fun YearMonth.toJavaYearMonth(): YearMonth

Converts this year-month to an equivalent Java YearMonth.
toNSDateComponents

darwin


fun YearMonth.toNSDateComponents(includeCalendar: Boolean = false): <ERROR CLASS>

Converts this year-month to an equivalent NSDateComponents object.
toYear

common


fun YearMonth.toYear(): Year

Returns this year-month with the precision reduced to the year.