Date using the international format defined by ISO 8601.

Usage:

var date = new ISODate
var tm = new Tm.localtime
assert date.year == tm.year + 1900
assert date.month == tm.mon + 1
assert date.day == tm.mday

# ISODate can be initialized from a String.
date = new ISODate.from_string("1970-01-01T00:00:00Z")
assert date.year == 1970
assert date.month == 1
assert date.day == 1

# ISODate can be printed as String following the ISO format.
assert date.to_s == "1970-01-01T00:00:00Z"

Note that only the YYYY-MM-DDTHH:MM:SSZ is supported for now.

See http://www.w3.org/QA/Tips/iso-date

Introduced properties

fun day: Int

core :: ISODate :: day

UTC days as Int (starting at 1).
protected fun day=(day: Int)

core :: ISODate :: day=

UTC days as Int (starting at 1).
init from_string(str: String)

core :: ISODate :: from_string

Init self from a ISODate formatted string.
fun hours: Int

core :: ISODate :: hours

UTC hours as Int.
protected fun hours=(hours: Int)

core :: ISODate :: hours=

UTC hours as Int.
fun minutes: Int

core :: ISODate :: minutes

UTC minutes as Int.
protected fun minutes=(minutes: Int)

core :: ISODate :: minutes=

UTC minutes as Int.
fun month: Int

core :: ISODate :: month

UTC months as Int (1 for January).
protected fun month=(month: Int)

core :: ISODate :: month=

UTC months as Int (1 for January).
fun seconds: Int

core :: ISODate :: seconds

UTC seconds as Int.
protected fun seconds=(seconds: Int)

core :: ISODate :: seconds=

UTC seconds as Int.
fun timezone: String

core :: ISODate :: timezone

UTC timezone marker.
protected fun timezone=(timezone: String)

core :: ISODate :: timezone=

UTC timezone marker.
fun year: Int

core :: ISODate :: year

UTC years as Int.
protected fun year=(year: Int)

core :: ISODate :: year=

UTC years as Int.

Redefined properties

redef fun <(o: OTHER): Bool

core $ ISODate :: <

TODO handle timezones
redef type OTHER: ISODate

core $ ISODate :: OTHER

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

core $ ISODate :: SELF

Type of this instance, automatically specialized in every class
redef init init

core $ ISODate :: init

redef fun to_s: String

core $ ISODate :: to_s

User readable representation of self.

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

core :: ISODate :: day

UTC days as Int (starting at 1).
protected fun day=(day: Int)

core :: ISODate :: day=

UTC days as Int (starting at 1).
init from_string(str: String)

core :: ISODate :: from_string

Init self from a ISODate formatted string.
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.
fun hours: Int

core :: ISODate :: hours

UTC hours as Int.
protected fun hours=(hours: Int)

core :: ISODate :: hours=

UTC hours as Int.
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 minutes: Int

core :: ISODate :: minutes

UTC minutes as Int.
protected fun minutes=(minutes: Int)

core :: ISODate :: minutes=

UTC minutes as Int.
fun month: Int

core :: ISODate :: month

UTC months as Int (1 for January).
protected fun month=(month: Int)

core :: ISODate :: month=

UTC months as Int (1 for January).
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 seconds: Int

core :: ISODate :: seconds

UTC seconds as Int.
protected fun seconds=(seconds: Int)

core :: ISODate :: seconds=

UTC seconds as Int.
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 timezone: String

core :: ISODate :: timezone

UTC timezone marker.
protected fun timezone=(timezone: String)

core :: ISODate :: timezone=

UTC timezone marker.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun year: Int

core :: ISODate :: year

UTC years as Int.
protected fun year=(year: Int)

core :: ISODate :: year=

UTC years as Int.
package_diagram core::ISODate ISODate core::Comparable Comparable core::ISODate->core::Comparable core::Object Object core::Comparable->core::Object ...core::Object ... ...core::Object->core::Object

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.

Class definitions

core $ ISODate
# Date using the international format defined by ISO 8601.
#
# Usage:
#
#     # By default ISODate at today.
#     var date = new ISODate
#     var tm = new Tm.localtime
#     assert date.year == tm.year + 1900
#     assert date.month == tm.mon + 1
#     assert date.day == tm.mday
#
#     # ISODate can be initialized from a String.
#     date = new ISODate.from_string("1970-01-01T00:00:00Z")
#     assert date.year == 1970
#     assert date.month == 1
#     assert date.day == 1
#
#     # ISODate can be printed as String following the ISO format.
#     assert date.to_s == "1970-01-01T00:00:00Z"
#
# Note that only the `YYYY-MM-DDTHH:MM:SSZ` is supported for now.
#
# See <http://www.w3.org/QA/Tips/iso-date>
class ISODate
	super Comparable

	# UTC years as Int.
	var year: Int is noinit

	# UTC months as Int (`1` for January).
	var month: Int is noinit

	# UTC days as Int (starting at `1`).
	var day: Int is noinit

	# UTC hours as Int.
	var hours: Int is noinit

	# UTC minutes as Int.
	var minutes: Int is noinit

	# UTC seconds as Int.
	var seconds: Int is noinit

	# UTC timezone marker.
	#
	# Note that I don't know what will happen if you change this value...
	var timezone = "Z"

	init do
		var t = new Tm.localtime
		year = 1900 + t.year
		month = t.mon + 1
		day = t.mday
		hours = t.hour
		minutes = t.min
		seconds = t.sec
	end

	# Init `self` from a ISODate formatted string.
	init from_string(str: String) do
		year = str.substring(0, 4).to_i
		month = str.substring(5, 2).to_i
		day = str.substring(8, 2).to_i
		hours = str.substring(11, 2).to_i
		minutes = str.substring(14, 2).to_i
		seconds = str.substring(17, 2).to_i
		timezone = str.substring(19, str.length)
	end

	redef fun to_s do
		var buff = new FlatBuffer
		buff.append year.to_s
		buff.add '-'
		if month < 10 then buff.add '0'
		buff.append month.to_s
		buff.add '-'
		if day < 10 then buff.add '0'
		buff.append day.to_s
		buff.add 'T'
		if hours < 10 then buff.add '0'
		buff.append hours.to_s
		buff.add ':'
		if minutes < 10 then buff.add '0'
		buff.append minutes.to_s
		buff.add ':'
		if seconds < 10 then buff.add '0'
		buff.append seconds.to_s
		buff.append timezone
		return buff.write_to_string
	end

	redef type OTHER: ISODate

	# TODO handle timezones
	redef fun <(o) do return to_s < o.to_s
end
lib/core/time.nit:183,1--279,3