hour
, a minute
and a second
countcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
date :: Time :: defaultinit
core :: Comparable :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# A time of the day, composed of an `hour`, a `minute` and a `second` count
class Time
super Comparable
redef type OTHER: Time
# The hour part of this time, between 0 and 23
var hour: Int
# The minute within the hour, between 0 and 59
var minute: Int
# The second within the minute, between 0 and 59
var second: Int
# Get the current time of the day
init now do
var tm = new Tm.localtime
init(tm.hour, tm.min, tm.sec)
end
# Get the difference between two times in second
fun diff_time(other: Time): Int do
return (hour * 3600 + minute * 60 + second) -
(other.hour * 3600 + other.minute * 60 + other.second)
end
redef fun ==(d) do return d isa Time and time_eq(d)
redef fun <(d) do return self.diff_time(d) < 0
redef fun hash do return hour * 1024 + minute * 64 + second
private fun time_eq(other: Time): Bool
do
return hour * 3600 + minute * 60 + second ==
other.hour * 3600 + other.minute * 60 + other.second
end
end
lib/date/date.nit:44,1--81,3