library / org.akop.kotx.types / DateTime

DateTime

open class DateTime : Parcelable, Comparable<DateTime>

DateTime is a thin wrapper around Calendar, designed to simplify the functionality and odd syntax of the latter. It delegates most of its internal functionality to Calendar in a way that maintains the object's immutability.

While DateTime mostly mirrors Calendar in its functionality, it does differ in some aspects - for instance, the first month in DateTime is numbered 1, not zero.

Constructors

<init>

DateTime(timeZoneId: String? = null)

Constructs a new DateTime object using specified time zone.

DateTime(calendar: Calendar)

Constructs a new DateTime object based on specified calendar instance.

DateTime(dateTime: DateTime)

Constructs a new DateTime object based on specified dateTime instance.

DateTime(millis: Long, timeZoneId: String? = null)

Constructs a new DateTime object with specified number of milliseconds since epoch.

DateTime(year: Int, month: Int, day: Int, hours: Int = 0, minutes: Int = 0, seconds: Int = 0, milliseconds: Int = 0, timeZoneId: String? = null)

Constructs a new DateTime object with specified year, month and day, and optionally hours, minutes, seconds and milliseconds.

DateTime(calendar: Calendar, clone: Boolean = false)

DateTime is a thin wrapper around Calendar, designed to simplify the functionality and odd syntax of the latter. It delegates most of its internal functionality to Calendar in a way that maintains the object's immutability.

Properties

day

open val day: Int

Returns day of month - first day is 1.

dayOfWeek

open val dayOfWeek: Int

Returns day of week - constants are identical to those used by Calendar.

hour

open val hour: Int

Returns hour within day - between 0 to 23.

milli

open val milli: Int

Returns millisecond within second.

millis

open val millis: Long

Returns UTC time in milliseconds since epoch.

minute

open val minute: Int

Returns minute within hour.

month

open val month: Int

Returns month of year - first month is 1.

second

open val second: Int

Returns second within minute.

timeZoneId

open val timeZoneId: String

Returns the time zone id for the instance.

year

open val year: Int

Returns year.

Functions

addedDays

fun addedDays(value: Int): DateTime

Returns an instance of DateTime resulting from adding value to day component. Value may be negative.

addedHours

fun addedHours(value: Int): DateTime

Returns an instance of DateTime resulting from adding value to hour component. Value may be negative.

addedMillis

fun addedMillis(value: Int): DateTime

Returns an instance of DateTime resulting from adding value to millisecond component. Value may be negative.

addedMinutes

fun addedMinutes(value: Int): DateTime

Returns an instance of DateTime resulting from adding value to minute component. Value may be negative.

addedMonths

fun addedMonths(value: Int): DateTime

Returns an instance of DateTime resulting from adding value to month component. Value may be negative.

addedSeconds

fun addedSeconds(value: Int): DateTime

Returns an instance of DateTime resulting from adding value to second component. Value may be negative.

addedYears

fun addedYears(value: Int): DateTime

Returns an instance of DateTime resulting from adding value to year component. Value may be negative.

after

infix fun after(other: DateTime): Boolean
infix fun after(other: Calendar): Boolean

Returns true if receiver falls after other.

infix fun after(other: Long): Boolean

Returns true if receiver falls after other - given in milliseconds since epoch.

before

infix fun before(other: DateTime): Boolean
infix fun before(other: Calendar): Boolean

Returns true if receiver falls before other.

infix fun before(other: Long): Boolean

Returns true if receiver falls before other - given in milliseconds since epoch.

compareTo

fun compareTo(other: Calendar): Int

Returns -1, 0, 1 if the instance is less than, equal to, or greater than specified Calendar instance, respectively.

fun compareTo(other: Long): Int

Returns -1, 0, 1 if the instance is less than, equal to, or greater than specified number of milliseconds from epoch, respectively.

open fun compareTo(other: DateTime): Int

Returns -1, 0, 1 if the instance is less than, equal to, or greater than other instance, respectively.

component1

operator fun component1(): Int

Returns year as the first component.

component2

operator fun component2(): Int

Returns month as the second component.

component3

operator fun component3(): Int

Returns day of month as the third component.

component4

operator fun component4(): Int

Returns hour of day as the fourth component.

component5

operator fun component5(): Int

Returns minute of hour as the fifth component.

component6

operator fun component6(): Int

Returns second of minute as the sixth component.

component7

operator fun component7(): Int

Returns millisecond of minute as the seventh component.

describeContents

open fun describeContents(): Int

Returns zero.

equals

open fun equals(other: Any?): Boolean

Returns true if the specified DateTime, Calendar, or Long (number of milliseconds from epoch) is equal to instance.

hashCode

open fun hashCode(): Int

Returns hash code of the instance - which is equal to its Calendar's hashCode value.

on

infix fun on(other: DateTime): Boolean
infix fun on(other: Calendar): Boolean
infix fun on(other: Long): Boolean

Returns true if receiver represents the same time as other.

onOrAfter

infix fun onOrAfter(other: DateTime): Boolean
infix fun onOrAfter(other: Calendar): Boolean

Returns true if receiver falls on or after other.

infix fun onOrAfter(other: Long): Boolean

Returns true if receiver falls on or after other - given in milliseconds since epoch.

onOrBefore

infix fun onOrBefore(other: DateTime): Boolean
infix fun onOrBefore(other: Calendar): Boolean

Returns true if receiver falls on or before other.

infix fun onOrBefore(other: Long): Boolean

Returns true if receiver falls on or before other - given in milliseconds since epoch.

toCalendar

fun toCalendar(): Calendar

Returns a clone of the Calendar object.

toMutable

open fun toMutable(): MutableDateTime

Returns a mutable version of the instance.

toString

fun toString(format: String, timeZoneId: String? = null): String

Returns a string representation of DateTime instance in specified format and optionally, time zone.

fun toString(format: DateFormat): String

Returns a string representation of DateTime instance in specified DateFormat.

open fun toString(): String

Returns a string representation of DateTime instance in RFC-3339 format, in UTC - e.g. "1983-07-15T08:00:59Z".

toTimeZone

fun toTimeZone(timeZoneId: String?): DateTime

Returns the DateTime instance in specified time zone.

toUTC

fun toUTC(): DateTime

Returns UTC representation of the DateTime instance.

truncatedTime

fun truncatedTime(): DateTime

Returns an instance of DateTime with hour, minute, second and millisecond components set to zero.

writeToParcel

open fun writeToParcel(dest: Parcel, flags: Int): Unit

Implements Parcelable.writeToParcel by writing number of milliseconds since epoch and time zone id.

Companion Object Properties

APRIL

const val APRIL: Int

AUGUST

const val AUGUST: Int

CREATOR

val CREATOR: Creator<DateTime>

Implementation of Parcelable.Creator.

DECEMBER

const val DECEMBER: Int

FEBRUARY

const val FEBRUARY: Int

FORMAT_RFC_3339

val FORMAT_RFC_3339: DateFormat

DateFormat instance representing RFC-3339.

FRIDAY

const val FRIDAY: Int

JANUARY

const val JANUARY: Int

JULY

const val JULY: Int

JUNE

const val JUNE: Int

MARCH

const val MARCH: Int

MAY

const val MAY: Int

MONDAY

const val MONDAY: Int

NOVEMBER

const val NOVEMBER: Int

OCTOBER

const val OCTOBER: Int

SATURDAY

const val SATURDAY: Int

SEPTEMBER

const val SEPTEMBER: Int

SUNDAY

const val SUNDAY: Int

THURSDAY

const val THURSDAY: Int

TUESDAY

const val TUESDAY: Int

WEDNESDAY

const val WEDNESDAY: Int

now

val now: DateTime

Returns DateTime instance representing current time and date.

today

val today: DateTime

Returns DateTime instance representing date. Time components will be set to zero.

Companion Object Functions

parse

fun parse(string: String, format: DateFormat): DateTime

Parses string in specified format and returns a DateTime instance.

tryParse

fun tryParse(string: String, format: DateFormat): DateTime?

Parses string in specified format and returns a DateTime instance, or null if parsing fails.

Inheritors

MutableDateTime

class MutableDateTime : DateTime

MutableDateTime is a mutable subclass of DateTime.