core :: Tm :: defaultinit
core :: Tm :: gmtime_from_timet
Create a new Time structure expressed in UTC fromt
.
core :: Tm :: localtime_from_timet
Create a new Time structure expressed in the local timezone fromt
.
core :: Pointer :: address_is_null
Is the address behind this Object at NULL?core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
core :: Pointer :: defaultinit
core :: Tm :: defaultinit
core :: Tm :: gmtime_from_timet
Create a new Time structure expressed in UTC fromt
.
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 :: Tm :: localtime_from_timet
Create a new Time structure expressed in the local timezone fromt
.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# Time structure
extern class Tm `{struct tm *`}
# Create a new Time structure expressed in Coordinated Universal Time (UTC).
new gmtime `{
struct tm *tm;
time_t t = time(NULL);
tm = gmtime(&t);
return tm;
`}
# Create a new Time structure expressed in UTC from `t`.
new gmtime_from_timet(t: TimeT) `{
struct tm *tm;
tm = gmtime(&t);
return tm;
`}
# Create a new Time structure expressed in the local timezone.
new localtime `{
struct tm *tm;
time_t t = time(NULL);
tm = localtime(&t);
return tm;
`}
# Create a new Time structure expressed in the local timezone from `t`.
new localtime_from_timet(t: TimeT) `{
struct tm *tm;
tm = localtime(&t);
return tm;
`}
# Convert `self` as a TimeT.
fun to_timet: TimeT `{ return mktime(self); `}
# Seconds after the minute.
fun sec: Int `{ return self->tm_sec; `}
# Minutes after the hour.
fun min: Int `{ return self->tm_min; `}
# hours since midnight.
fun hour: Int `{ return self->tm_hour; `}
# Day of the month.
fun mday: Int `{ return self->tm_mday; `}
# Months since January.
fun mon: Int `{ return self->tm_mon; `}
# Years since 1900.
fun year: Int `{ return self->tm_year; `}
# Days since Sunday.
fun wday: Int `{ return self->tm_wday; `}
# Days since January 1st.
fun yday: Int `{ return self->tm_yday; `}
# Is `self` in Daylight Saving Time.
fun is_dst: Bool `{ return self->tm_isdst; `}
# Convert `self` to a human readable String.
private fun asctime: CString `{ return asctime(self); `}
# Convert `self` to a human readable String corresponding to `format`.
# TODO document allowed format.
fun strftime(format: String): String import String.to_cstring, CString.to_s `{
char* buf, *c_format;
buf = (char*)malloc(100);
c_format = String_to_cstring(format);
strftime(buf, 100, c_format, self);
String s = CString_to_s(buf);
free(buf);
return s;
`}
redef fun to_s do return asctime.to_s.replace("\n", "")
end
lib/core/time.nit:100,1--181,3