Property definitions

core $ Tm :: defaultinit
# 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