A date, composed by a year, a month and a day

Introduced properties

fun day: Int

date :: Date :: day

Day of the month
protected fun day=(day: Int)

date :: Date :: day=

Day of the month
init defaultinit(year: Int, month: Int, day: Int)

date :: Date :: defaultinit

fun diff_days(other: Date): Int

date :: Date :: diff_days

Difference in days between self and other
fun diff_months(other: Date): Int

date :: Date :: diff_months

Difference in months between self and other
fun diff_years(other: Date): Int

date :: Date :: diff_years

Difference in years between self and other
fun month: Int

date :: Date :: month

Month as an integer, 1 for January, 2 for February, etc.
protected fun month=(month: Int)

date :: Date :: month=

Month as an integer, 1 for January, 2 for February, etc.
fun time_zone: String

date :: Date :: time_zone

UTC time zone
protected fun time_zone=(time_zone: String)

date :: Date :: time_zone=

UTC time zone
init today

date :: Date :: today

The date of this day
fun year: Int

date :: Date :: year

Year, ex: 1989
protected fun year=(year: Int)

date :: Date :: year=

Year, ex: 1989

Redefined properties

redef fun <(d: OTHER): Bool

date $ Date :: <

Is self lesser than other?
redef fun ==(d: nullable Object): Bool

date $ Date :: ==

Have self and other the same value?
redef type OTHER: Date

date $ Date :: OTHER

What self can be compared to?
redef type SELF: Date

date $ Date :: SELF

Type of this instance, automatically specialized in every class
redef fun hash: Int

date $ Date :: hash

The hash code of the object.
redef fun is_between(a: OTHER, b: OTHER): Bool

date $ Date :: is_between

Is self between a and b?
redef fun to_s: String

date $ Date :: to_s

self formatted according to ISO 8601

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
abstract fun <(other: OTHER): Bool

core :: Comparable :: <

Is self lesser than other?
fun <=(other: OTHER): Bool

core :: Comparable :: <=

not other < self
fun <=>(other: OTHER): Int

core :: Comparable :: <=>

-1 if <, +1 if > and 0 otherwise
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
fun >(other: OTHER): Bool

core :: Comparable :: >

other < self
fun >=(other: OTHER): Bool

core :: Comparable :: >=

not self < other
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type OTHER: Comparable

core :: Comparable :: OTHER

What self can be compared to?
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun clamp(min: OTHER, max: OTHER): OTHER

core :: Comparable :: clamp

Constraint self within [min..max]
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun day: Int

date :: Date :: day

Day of the month
protected fun day=(day: Int)

date :: Date :: day=

Day of the month
init defaultinit(year: Int, month: Int, day: Int)

date :: Date :: defaultinit

fun diff_days(other: Date): Int

date :: Date :: diff_days

Difference in days between self and other
fun diff_months(other: Date): Int

date :: Date :: diff_months

Difference in months between self and other
fun diff_years(other: Date): Int

date :: Date :: diff_years

Difference in years between self and other
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun is_between(c: OTHER, d: OTHER): Bool

core :: Comparable :: is_between

c <= self <= d
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun max(other: OTHER): OTHER

core :: Comparable :: max

The maximum between self and other (prefers self if equals).
fun min(c: OTHER): OTHER

core :: Comparable :: min

The minimum between self and c (prefer self if equals)
fun month: Int

date :: Date :: month

Month as an integer, 1 for January, 2 for February, etc.
protected fun month=(month: Int)

date :: Date :: month=

Month as an integer, 1 for January, 2 for February, etc.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun time_zone: String

date :: Date :: time_zone

UTC time zone
protected fun time_zone=(time_zone: String)

date :: Date :: time_zone=

UTC time zone
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
init today

date :: Date :: today

The date of this day
fun year: Int

date :: Date :: year

Year, ex: 1989
protected fun year=(year: Int)

date :: Date :: year=

Year, ex: 1989
package_diagram date::Date Date core::Comparable Comparable date::Date->core::Comparable core::Object Object core::Comparable->core::Object ...core::Object ... ...core::Object->core::Object date::DateTime DateTime date::DateTime->date::Date

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

interface Comparable

core :: Comparable

The ancestor of class where objects are in a total order.

Children

class DateTime

date :: DateTime

A Time in a Date

Class definitions

date $ Date
# A date, composed by a `year`, a `month` and a `day`
class Date
	super Comparable
	redef type OTHER: Date

	# Year, ex: 1989
	var year: Int

	# Month as an integer, `1` for January, `2` for February, etc.
	var month: Int

	# Day of the month
	var day: Int

	# UTC time zone
	#
	# FIXME this value is not yet applied
	var time_zone = "Z"

	# The date of this day
	init today do
		var tm = new Tm.localtime
		init(1900 + tm.year, tm.mon + 1, tm.mday)
	end

	# `self` formatted according to ISO 8601
	redef fun to_s do return "{year}-{month}-{day}"

	# Difference in days between `self` and `other`
	fun diff_days(other: Date): Int
	do
		var y_out = year - other.year
		y_out = y_out * 365
		var m_out = month - other.month
		m_out = m_out * 30 # FIXME
		return day - other.day + m_out + y_out
	end

	# Difference in months between `self` and `other`
	fun diff_months(other: Date): Int
	do
		var y_out = year - other.year
		y_out = y_out * 12
		return month - other.month + y_out
	end

	# Difference in years between `self` and `other`
	fun diff_years(other: Date): Int do return year - other.year

	redef fun ==(d) do return d isa Date and self.diff_days(d) == 0

	redef fun hash do return year + month * 1024 + day * 2048

	redef fun <(d) do return self.diff_days(d) < 0

	# Is `self` is between the years of `a` and `b`?
	private fun is_between_years(a, b: Date): Bool
	do
		return (a.year > year and b.year < year) or (b.year > year and a.year < year) or (a.year == year or b.year == year)
	end

	# Is `self` is between the months of `a` and `b`?
	private fun is_between_months(a, b: Date) : Bool
	do
		if not self.is_between_years(a,b) then return false
		return (a.month > month and b.month < month) or (b.month > month and a.month < month) or (a.month == month or b.month == month)
	end

	# Is `self` between `a` and `b`?
	redef fun is_between(a, b)
	do
		if not self.is_between_months(a, b) then return false
		return (a.day > day and b.day < day) or (b.day > day and a.day < day) or (a.day == day or b.day == day)
	end
end
lib/date/date.nit:83,1--157,3