4 ** See Copyright Notice in mruby.h
10 #include <mruby/class.h>
11 #include <mruby/data.h>
12 #include <mruby/time.h>
14 #ifndef MRB_DISABLE_STDIO
20 #define NDIV(x,y) (-(-((x)+1)/(y))-1)
22 #if defined(_MSC_VER) && _MSC_VER < 1800
23 double round(double x) {
24 return floor(x + 0.5);
28 #if !defined(__MINGW64__) && defined(_WIN32)
29 # define llround(x) round(x)
32 #if defined(__MINGW64__) || defined(__MINGW32__)
33 # include <sys/time.h>
36 /** Time class configuration */
39 /* C99 does not have gettimeofday that is required to retrieve microseconds */
40 /* uncomment following macro on platforms without gettimeofday(2) */
41 /* #define NO_GETTIMEOFDAY */
44 /* C99 does not have reentrant gmtime_r() so it might cause troubles under */
45 /* multi-threading environment. undef following macro on platforms that */
46 /* does not have gmtime_r() and localtime_r(). */
47 /* #define NO_GMTIME_R */
51 /* Win32 platform do not provide gmtime_r/localtime_r; emulate them using gmtime_s/localtime_s */
52 #define gmtime_r(tp, tm) ((gmtime_s((tm), (tp)) == 0) ? (tm) : NULL)
53 #define localtime_r(tp, tm) ((localtime_s((tm), (tp)) == 0) ? (tm) : NULL)
60 /* mruby usually use its own implementation of struct tm to string conversion */
61 /* except when DISABLE_STDIO is set. In that case, it uses asctime() or asctime_r(). */
62 /* By default mruby tries to use asctime_r() which is reentrant. */
63 /* Undef following macro on platforms that does not have asctime_r(). */
64 /* #define NO_ASCTIME_R */
67 /* mktime() creates tm structure for localtime; timegm() is for UTC time */
68 /* define following macro to use probably faster timegm() on the platform */
69 /* #define USE_SYSTEM_TIMEGM */
72 /* If your platform supports time_t as uint (e.g. uint32_t, uint64_t), */
73 /* uncomment following macro. */
74 /* #define MRB_TIME_T_UINT */
76 /** end of Time class configuration */
78 #ifndef NO_GETTIMEOFDAY
80 # define WIN32_LEAN_AND_MEAN /* don't include winsock.h */
82 # define gettimeofday my_gettimeofday
85 # define UI64(x) x##ui64
87 # define UI64(x) x##ull
90 typedef long suseconds_t;
92 # if (!defined __MINGW64__) && (!defined __MINGW32__)
100 gettimeofday(struct timeval *tv, void *tz)
103 mrb_assert(0); /* timezone is not supported */
108 unsigned __int64 u64;
110 GetSystemTimeAsFileTime(&t.ft); /* 100 ns intervals since Windows epoch */
111 t.u64 -= UI64(116444736000000000); /* Unix epoch bias */
112 t.u64 /= 10; /* to microseconds */
113 tv->tv_sec = (time_t)(t.u64 / (1000 * 1000));
114 tv->tv_usec = t.u64 % (1000 * 1000);
119 # include <sys/time.h>
123 #define gmtime_r(t,r) gmtime(t)
124 #define localtime_r(t,r) localtime(t)
127 #ifndef USE_SYSTEM_TIMEGM
128 #define timegm my_timgm
131 is_leapyear(unsigned int y)
133 return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0);
137 timegm(struct tm *tm)
139 static const unsigned int ndays[2][12] = {
140 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
141 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
145 unsigned int *nday = (unsigned int*) ndays[is_leapyear(tm->tm_year+1900)];
147 static const int epoch_year = 70;
148 if(tm->tm_year >= epoch_year) {
149 for (i = epoch_year; i < tm->tm_year; ++i)
150 r += is_leapyear(i+1900) ? 366*24*60*60 : 365*24*60*60;
152 for (i = tm->tm_year; i < epoch_year; ++i)
153 r -= is_leapyear(i+1900) ? 366*24*60*60 : 365*24*60*60;
155 for (i = 0; i < tm->tm_mon; ++i)
156 r += nday[i] * 24 * 60 * 60;
157 r += (tm->tm_mday - 1) * 24 * 60 * 60;
158 r += tm->tm_hour * 60 * 60;
159 r += tm->tm_min * 60;
165 /* Since we are limited to using ISO C99, this implementation is based
166 * on time_t. That means the resolution of time is only precise to the
167 * second level. Also, there are only 2 timezones, namely UTC and LOCAL.
170 typedef struct mrb_timezone_name {
175 static const mrb_timezone_name timezone_names[] = {
176 { "none", sizeof("none") - 1 },
177 { "UTC", sizeof("UTC") - 1 },
178 { "LOCAL", sizeof("LOCAL") - 1 },
181 #ifndef MRB_DISABLE_STDIO
182 static const char mon_names[12][4] = {
183 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
186 static const char wday_names[7][4] = {
187 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
194 enum mrb_timezone timezone;
198 static const struct mrb_data_type mrb_time_type = { "Time", mrb_free };
200 /** Updates the datetime of a mrb_time based on it's timezone and
201 seconds setting. Returns self on success, NULL of failure.
202 if `dealloc` is set `true`, it frees `self` on error. */
203 static struct mrb_time*
204 time_update_datetime(mrb_state *mrb, struct mrb_time *self, int dealloc)
208 if (self->timezone == MRB_TIMEZONE_UTC) {
209 aid = gmtime_r(&self->sec, &self->datetime);
212 aid = localtime_r(&self->sec, &self->datetime);
215 mrb_float sec = (mrb_float)self->sec;
218 mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", mrb_float_value(mrb, sec));
223 self->datetime = *aid; /* copy data */
230 mrb_time_wrap(mrb_state *mrb, struct RClass *tc, struct mrb_time *tm)
232 return mrb_obj_value(Data_Wrap_Struct(mrb, tc, &mrb_time_type, tm));
235 void mrb_check_num_exact(mrb_state *mrb, mrb_float num);
237 /* Allocates a mrb_time object and initializes it. */
238 static struct mrb_time*
239 time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
244 mrb_check_num_exact(mrb, (mrb_float)sec);
245 mrb_check_num_exact(mrb, (mrb_float)usec);
246 #ifndef MRB_TIME_T_UINT
247 if (sizeof(time_t) == 4 && (sec > (double)INT32_MAX || (double)INT32_MIN > sec)) {
250 if (sizeof(time_t) == 8 && (sec > (double)INT64_MAX || (double)INT64_MIN > sec)) {
254 if (sizeof(time_t) == 4 && (sec > (double)UINT32_MAX || (double)0 > sec)) {
257 if (sizeof(time_t) == 8 && (sec > (double)UINT64_MAX || (double)0 > sec)) {
262 if ((sec > 0 && tsec < 0) || (sec < 0 && (double)tsec > sec)) {
264 mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", mrb_float_value(mrb, sec));
266 tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time));
268 tm->usec = (time_t)llround((sec - tm->sec) * 1.0e6 + usec);
270 long sec2 = (long)NDIV(tm->usec,1000000); /* negative div */
271 tm->usec -= sec2 * 1000000;
274 else if (tm->usec >= 1000000) {
275 long sec2 = (long)(tm->usec / 1000000);
276 tm->usec -= sec2 * 1000000;
279 tm->timezone = timezone;
280 time_update_datetime(mrb, tm, TRUE);
286 mrb_time_make(mrb_state *mrb, struct RClass *c, double sec, double usec, enum mrb_timezone timezone)
288 return mrb_time_wrap(mrb, c, time_alloc(mrb, sec, usec, timezone));
291 static struct mrb_time*
292 current_mrb_time(mrb_state *mrb)
296 tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm));
297 #if defined(TIME_UTC) && !defined(__ANDROID__)
300 if (timespec_get(&ts, TIME_UTC) == 0) {
302 mrb_raise(mrb, E_RUNTIME_ERROR, "timespec_get() failed for unknown reasons");
305 tm->usec = ts.tv_nsec / 1000;
307 #elif defined(NO_GETTIMEOFDAY)
309 static time_t last_sec = 0, last_usec = 0;
311 tm->sec = time(NULL);
312 if (tm->sec != last_sec) {
317 /* add 1 usec to differentiate two times */
320 tm->usec = last_usec;
326 gettimeofday(&tv, NULL);
328 tm->usec = tv.tv_usec;
331 tm->timezone = MRB_TIMEZONE_LOCAL;
332 time_update_datetime(mrb, tm, TRUE);
337 /* Allocates a new Time object with given millis value. */
339 mrb_time_now(mrb_state *mrb, mrb_value self)
341 return mrb_time_wrap(mrb, mrb_class_ptr(self), current_mrb_time(mrb));
345 mrb_time_at(mrb_state *mrb, double sec, double usec, enum mrb_timezone zone)
347 return mrb_time_make(mrb, mrb_class_get(mrb, "Time"), sec, usec, zone);
351 /* Creates an instance of time at the given time in seconds, etc. */
353 mrb_time_at_m(mrb_state *mrb, mrb_value self)
357 mrb_get_args(mrb, "f|f", &f, &f2);
358 return mrb_time_make(mrb, mrb_class_ptr(self), f, f2, MRB_TIMEZONE_LOCAL);
361 static struct mrb_time*
362 time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
363 mrb_int ahour, mrb_int amin, mrb_int asec, mrb_int ausec,
364 enum mrb_timezone timezone)
367 struct tm nowtime = { 0 };
369 nowtime.tm_year = (int)ayear - 1900;
370 nowtime.tm_mon = (int)amonth - 1;
371 nowtime.tm_mday = (int)aday;
372 nowtime.tm_hour = (int)ahour;
373 nowtime.tm_min = (int)amin;
374 nowtime.tm_sec = (int)asec;
375 nowtime.tm_isdst = -1;
377 if (nowtime.tm_mon < 0 || nowtime.tm_mon > 11
378 || nowtime.tm_mday < 1 || nowtime.tm_mday > 31
379 || nowtime.tm_hour < 0 || nowtime.tm_hour > 24
380 || (nowtime.tm_hour == 24 && (nowtime.tm_min > 0 || nowtime.tm_sec > 0))
381 || nowtime.tm_min < 0 || nowtime.tm_min > 59
382 || nowtime.tm_sec < 0 || nowtime.tm_sec > 60)
383 mrb_raise(mrb, E_RUNTIME_ERROR, "argument out of range");
385 if (timezone == MRB_TIMEZONE_UTC) {
386 nowsecs = timegm(&nowtime);
389 nowsecs = mktime(&nowtime);
391 if (nowsecs == (time_t)-1) {
392 mrb_raise(mrb, E_ARGUMENT_ERROR, "Not a valid time.");
395 return time_alloc(mrb, (double)nowsecs, (double)ausec, timezone);
399 /* Creates an instance of time at the given time in UTC. */
401 mrb_time_gm(mrb_state *mrb, mrb_value self)
403 mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, amin = 0, asec = 0, ausec = 0;
405 mrb_get_args(mrb, "i|iiiiii",
406 &ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
407 return mrb_time_wrap(mrb, mrb_class_ptr(self),
408 time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_UTC));
413 /* Creates an instance of time at the given time in local time zone. */
415 mrb_time_local(mrb_state *mrb, mrb_value self)
417 mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, amin = 0, asec = 0, ausec = 0;
419 mrb_get_args(mrb, "i|iiiiii",
420 &ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
421 return mrb_time_wrap(mrb, mrb_class_ptr(self),
422 time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_LOCAL));
425 static struct mrb_time*
426 time_get_ptr(mrb_state *mrb, mrb_value time)
430 tm = DATA_GET_PTR(mrb, time, &mrb_time_type, struct mrb_time);
432 mrb_raise(mrb, E_ARGUMENT_ERROR, "uninitialized time");
438 mrb_time_eq(mrb_state *mrb, mrb_value self)
441 struct mrb_time *tm1, *tm2;
444 mrb_get_args(mrb, "o", &other);
445 tm1 = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time);
446 tm2 = DATA_CHECK_GET_PTR(mrb, other, &mrb_time_type, struct mrb_time);
447 eq_p = tm1 && tm2 && tm1->sec == tm2->sec && tm1->usec == tm2->usec;
449 return mrb_bool_value(eq_p);
453 mrb_time_cmp(mrb_state *mrb, mrb_value self)
456 struct mrb_time *tm1, *tm2;
458 mrb_get_args(mrb, "o", &other);
459 tm1 = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time);
460 tm2 = DATA_CHECK_GET_PTR(mrb, other, &mrb_time_type, struct mrb_time);
461 if (!tm1 || !tm2) return mrb_nil_value();
462 if (tm1->sec > tm2->sec) {
463 return mrb_fixnum_value(1);
465 else if (tm1->sec < tm2->sec) {
466 return mrb_fixnum_value(-1);
468 /* tm1->sec == tm2->sec */
469 if (tm1->usec > tm2->usec) {
470 return mrb_fixnum_value(1);
472 else if (tm1->usec < tm2->usec) {
473 return mrb_fixnum_value(-1);
475 return mrb_fixnum_value(0);
479 mrb_time_plus(mrb_state *mrb, mrb_value self)
484 mrb_get_args(mrb, "f", &f);
485 tm = time_get_ptr(mrb, self);
486 return mrb_time_make(mrb, mrb_obj_class(mrb, self), (double)tm->sec+f, (double)tm->usec, tm->timezone);
490 mrb_time_minus(mrb_state *mrb, mrb_value self)
494 struct mrb_time *tm, *tm2;
496 mrb_get_args(mrb, "o", &other);
497 tm = time_get_ptr(mrb, self);
498 tm2 = DATA_CHECK_GET_PTR(mrb, other, &mrb_time_type, struct mrb_time);
500 f = (mrb_float)(tm->sec - tm2->sec)
501 + (mrb_float)(tm->usec - tm2->usec) / 1.0e6;
502 return mrb_float_value(mrb, f);
505 mrb_get_args(mrb, "f", &f);
506 return mrb_time_make(mrb, mrb_obj_class(mrb, self), (double)tm->sec-f, (double)tm->usec, tm->timezone);
511 /* Returns week day number of time. */
513 mrb_time_wday(mrb_state *mrb, mrb_value self)
517 tm = time_get_ptr(mrb, self);
518 return mrb_fixnum_value(tm->datetime.tm_wday);
522 /* Returns year day number of time. */
524 mrb_time_yday(mrb_state *mrb, mrb_value self)
528 tm = time_get_ptr(mrb, self);
529 return mrb_fixnum_value(tm->datetime.tm_yday + 1);
533 /* Returns year of time. */
535 mrb_time_year(mrb_state *mrb, mrb_value self)
539 tm = time_get_ptr(mrb, self);
540 return mrb_fixnum_value(tm->datetime.tm_year + 1900);
544 /* Returns name of time's timezone. */
546 mrb_time_zone(mrb_state *mrb, mrb_value self)
550 tm = time_get_ptr(mrb, self);
551 if (tm->timezone <= MRB_TIMEZONE_NONE) return mrb_nil_value();
552 if (tm->timezone >= MRB_TIMEZONE_LAST) return mrb_nil_value();
553 return mrb_str_new_static(mrb,
554 timezone_names[tm->timezone].name,
555 timezone_names[tm->timezone].len);
559 /* Returns a string that describes the time. */
561 mrb_time_asctime(mrb_state *mrb, mrb_value self)
563 struct mrb_time *tm = time_get_ptr(mrb, self);
564 struct tm *d = &tm->datetime;
567 #if defined(MRB_DISABLE_STDIO)
573 s = asctime_r(d, buf);
575 len = strlen(s)-1; /* truncate the last newline */
579 len = snprintf(buf, sizeof(buf), "%s %s %02d %02d:%02d:%02d %s%d",
580 wday_names[d->tm_wday], mon_names[d->tm_mon], d->tm_mday,
581 d->tm_hour, d->tm_min, d->tm_sec,
582 tm->timezone == MRB_TIMEZONE_UTC ? "UTC " : "",
585 return mrb_str_new(mrb, buf, len);
589 /* Returns the day in the month of the time. */
591 mrb_time_day(mrb_state *mrb, mrb_value self)
595 tm = time_get_ptr(mrb, self);
596 return mrb_fixnum_value(tm->datetime.tm_mday);
601 /* Returns true if daylight saving was applied for this time. */
603 mrb_time_dst_p(mrb_state *mrb, mrb_value self)
607 tm = time_get_ptr(mrb, self);
608 return mrb_bool_value(tm->datetime.tm_isdst);
613 /* Returns the Time object of the UTC(GMT) timezone. */
615 mrb_time_getutc(mrb_state *mrb, mrb_value self)
617 struct mrb_time *tm, *tm2;
619 tm = time_get_ptr(mrb, self);
620 tm2 = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm));
622 tm2->timezone = MRB_TIMEZONE_UTC;
623 time_update_datetime(mrb, tm2, TRUE);
624 return mrb_time_wrap(mrb, mrb_obj_class(mrb, self), tm2);
628 /* Returns the Time object of the LOCAL timezone. */
630 mrb_time_getlocal(mrb_state *mrb, mrb_value self)
632 struct mrb_time *tm, *tm2;
634 tm = time_get_ptr(mrb, self);
635 tm2 = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm));
637 tm2->timezone = MRB_TIMEZONE_LOCAL;
638 time_update_datetime(mrb, tm2, TRUE);
639 return mrb_time_wrap(mrb, mrb_obj_class(mrb, self), tm2);
643 /* Returns hour of time. */
645 mrb_time_hour(mrb_state *mrb, mrb_value self)
649 tm = time_get_ptr(mrb, self);
650 return mrb_fixnum_value(tm->datetime.tm_hour);
654 /* Initializes a time by setting the amount of milliseconds since the epoch.*/
656 mrb_time_initialize(mrb_state *mrb, mrb_value self)
658 mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0,
659 amin = 0, asec = 0, ausec = 0;
663 n = mrb_get_args(mrb, "|iiiiiii",
664 &ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
665 tm = (struct mrb_time*)DATA_PTR(self);
669 mrb_data_init(self, NULL, &mrb_time_type);
672 tm = current_mrb_time(mrb);
675 tm = time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_LOCAL);
677 mrb_data_init(self, tm, &mrb_time_type);
681 /* 15.2.19.7.17(x) */
682 /* Initializes a copy of this time object. */
684 mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy)
687 struct mrb_time *t1, *t2;
689 mrb_get_args(mrb, "o", &src);
690 if (mrb_obj_equal(mrb, copy, src)) return copy;
691 if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
692 mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
694 t1 = (struct mrb_time *)DATA_PTR(copy);
695 t2 = (struct mrb_time *)DATA_PTR(src);
697 mrb_raise(mrb, E_ARGUMENT_ERROR, "uninitialized time");
700 t1 = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time));
701 mrb_data_init(copy, t1, &mrb_time_type);
708 /* Sets the timezone attribute of the Time object to LOCAL. */
710 mrb_time_localtime(mrb_state *mrb, mrb_value self)
714 tm = time_get_ptr(mrb, self);
715 tm->timezone = MRB_TIMEZONE_LOCAL;
716 time_update_datetime(mrb, tm, FALSE);
721 /* Returns day of month of time. */
723 mrb_time_mday(mrb_state *mrb, mrb_value self)
727 tm = time_get_ptr(mrb, self);
728 return mrb_fixnum_value(tm->datetime.tm_mday);
732 /* Returns minutes of time. */
734 mrb_time_min(mrb_state *mrb, mrb_value self)
738 tm = time_get_ptr(mrb, self);
739 return mrb_fixnum_value(tm->datetime.tm_min);
742 /* 15.2.19.7.21 and 15.2.19.7.22 */
743 /* Returns month of time. */
745 mrb_time_mon(mrb_state *mrb, mrb_value self)
749 tm = time_get_ptr(mrb, self);
750 return mrb_fixnum_value(tm->datetime.tm_mon + 1);
754 /* Returns seconds in minute of time. */
756 mrb_time_sec(mrb_state *mrb, mrb_value self)
760 tm = time_get_ptr(mrb, self);
761 return mrb_fixnum_value(tm->datetime.tm_sec);
766 /* Returns a Float with the time since the epoch in seconds. */
768 mrb_time_to_f(mrb_state *mrb, mrb_value self)
772 tm = time_get_ptr(mrb, self);
773 return mrb_float_value(mrb, (mrb_float)tm->sec + (mrb_float)tm->usec/1.0e6);
777 /* Returns a Fixnum with the time since the epoch in seconds. */
779 mrb_time_to_i(mrb_state *mrb, mrb_value self)
783 tm = time_get_ptr(mrb, self);
784 if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) {
785 return mrb_float_value(mrb, (mrb_float)tm->sec);
787 return mrb_fixnum_value((mrb_int)tm->sec);
791 /* Returns a Float with the time since the epoch in microseconds. */
793 mrb_time_usec(mrb_state *mrb, mrb_value self)
797 tm = time_get_ptr(mrb, self);
798 if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) {
799 return mrb_float_value(mrb, (mrb_float)tm->usec);
801 return mrb_fixnum_value((mrb_int)tm->usec);
805 /* Sets the timezone attribute of the Time object to UTC. */
807 mrb_time_utc(mrb_state *mrb, mrb_value self)
811 tm = time_get_ptr(mrb, self);
812 tm->timezone = MRB_TIMEZONE_UTC;
813 time_update_datetime(mrb, tm, FALSE);
818 /* Returns true if this time is in the UTC timezone false if not. */
820 mrb_time_utc_p(mrb_state *mrb, mrb_value self)
824 tm = time_get_ptr(mrb, self);
825 return mrb_bool_value(tm->timezone == MRB_TIMEZONE_UTC);
830 mrb_mruby_time_gem_init(mrb_state* mrb)
834 tc = mrb_define_class(mrb, "Time", mrb->object_class);
835 MRB_SET_INSTANCE_TT(tc, MRB_TT_DATA);
836 mrb_include_module(mrb, tc, mrb_module_get(mrb, "Comparable"));
837 mrb_define_class_method(mrb, tc, "at", mrb_time_at_m, MRB_ARGS_ARG(1, 1)); /* 15.2.19.6.1 */
838 mrb_define_class_method(mrb, tc, "gm", mrb_time_gm, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.2 */
839 mrb_define_class_method(mrb, tc, "local", mrb_time_local, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.3 */
840 mrb_define_class_method(mrb, tc, "mktime", mrb_time_local, MRB_ARGS_ARG(1,6));/* 15.2.19.6.4 */
841 mrb_define_class_method(mrb, tc, "now", mrb_time_now, MRB_ARGS_NONE()); /* 15.2.19.6.5 */
842 mrb_define_class_method(mrb, tc, "utc", mrb_time_gm, MRB_ARGS_ARG(1,6)); /* 15.2.19.6.6 */
844 mrb_define_method(mrb, tc, "==" , mrb_time_eq , MRB_ARGS_REQ(1));
845 mrb_define_method(mrb, tc, "<=>" , mrb_time_cmp , MRB_ARGS_REQ(1)); /* 15.2.19.7.1 */
846 mrb_define_method(mrb, tc, "+" , mrb_time_plus , MRB_ARGS_REQ(1)); /* 15.2.19.7.2 */
847 mrb_define_method(mrb, tc, "-" , mrb_time_minus , MRB_ARGS_REQ(1)); /* 15.2.19.7.3 */
848 mrb_define_method(mrb, tc, "to_s" , mrb_time_asctime, MRB_ARGS_NONE());
849 mrb_define_method(mrb, tc, "inspect", mrb_time_asctime, MRB_ARGS_NONE());
850 mrb_define_method(mrb, tc, "asctime", mrb_time_asctime, MRB_ARGS_NONE()); /* 15.2.19.7.4 */
851 mrb_define_method(mrb, tc, "ctime" , mrb_time_asctime, MRB_ARGS_NONE()); /* 15.2.19.7.5 */
852 mrb_define_method(mrb, tc, "day" , mrb_time_day , MRB_ARGS_NONE()); /* 15.2.19.7.6 */
853 mrb_define_method(mrb, tc, "dst?" , mrb_time_dst_p , MRB_ARGS_NONE()); /* 15.2.19.7.7 */
854 mrb_define_method(mrb, tc, "getgm" , mrb_time_getutc , MRB_ARGS_NONE()); /* 15.2.19.7.8 */
855 mrb_define_method(mrb, tc, "getlocal",mrb_time_getlocal,MRB_ARGS_NONE()); /* 15.2.19.7.9 */
856 mrb_define_method(mrb, tc, "getutc" , mrb_time_getutc , MRB_ARGS_NONE()); /* 15.2.19.7.10 */
857 mrb_define_method(mrb, tc, "gmt?" , mrb_time_utc_p , MRB_ARGS_NONE()); /* 15.2.19.7.11 */
858 mrb_define_method(mrb, tc, "gmtime" , mrb_time_utc , MRB_ARGS_NONE()); /* 15.2.19.7.13 */
859 mrb_define_method(mrb, tc, "hour" , mrb_time_hour, MRB_ARGS_NONE()); /* 15.2.19.7.15 */
860 mrb_define_method(mrb, tc, "localtime", mrb_time_localtime, MRB_ARGS_NONE()); /* 15.2.19.7.18 */
861 mrb_define_method(mrb, tc, "mday" , mrb_time_mday, MRB_ARGS_NONE()); /* 15.2.19.7.19 */
862 mrb_define_method(mrb, tc, "min" , mrb_time_min, MRB_ARGS_NONE()); /* 15.2.19.7.20 */
864 mrb_define_method(mrb, tc, "mon" , mrb_time_mon, MRB_ARGS_NONE()); /* 15.2.19.7.21 */
865 mrb_define_method(mrb, tc, "month", mrb_time_mon, MRB_ARGS_NONE()); /* 15.2.19.7.22 */
867 mrb_define_method(mrb, tc, "sec" , mrb_time_sec, MRB_ARGS_NONE()); /* 15.2.19.7.23 */
868 mrb_define_method(mrb, tc, "to_i", mrb_time_to_i, MRB_ARGS_NONE()); /* 15.2.19.7.25 */
869 mrb_define_method(mrb, tc, "to_f", mrb_time_to_f, MRB_ARGS_NONE()); /* 15.2.19.7.24 */
870 mrb_define_method(mrb, tc, "usec", mrb_time_usec, MRB_ARGS_NONE()); /* 15.2.19.7.26 */
871 mrb_define_method(mrb, tc, "utc" , mrb_time_utc, MRB_ARGS_NONE()); /* 15.2.19.7.27 */
872 mrb_define_method(mrb, tc, "utc?", mrb_time_utc_p,MRB_ARGS_NONE()); /* 15.2.19.7.28 */
873 mrb_define_method(mrb, tc, "wday", mrb_time_wday, MRB_ARGS_NONE()); /* 15.2.19.7.30 */
874 mrb_define_method(mrb, tc, "yday", mrb_time_yday, MRB_ARGS_NONE()); /* 15.2.19.7.31 */
875 mrb_define_method(mrb, tc, "year", mrb_time_year, MRB_ARGS_NONE()); /* 15.2.19.7.32 */
876 mrb_define_method(mrb, tc, "zone", mrb_time_zone, MRB_ARGS_NONE()); /* 15.2.19.7.33 */
878 mrb_define_method(mrb, tc, "initialize", mrb_time_initialize, MRB_ARGS_REQ(1)); /* 15.2.19.7.16 */
879 mrb_define_method(mrb, tc, "initialize_copy", mrb_time_initialize_copy, MRB_ARGS_REQ(1)); /* 15.2.19.7.17 */
882 methods not available:
883 gmt_offset(15.2.19.7.12)
885 utc_offset(15.2.19.7.29)
890 mrb_mruby_time_gem_final(mrb_state* mrb)