summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-22 13:53:20 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-22 13:53:20 (GMT)
commit385b7721494abf8e50d57db33cbd358abb0d780f (patch)
tree439328130462ea2fea986241e8cf625fa5ddc993 /time.c
parentf289e3994bbc6560e2e4e5905b52c35c829c972d (diff)
Return fixed values at subsec, utc_offset, and isdst
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/time.c b/time.c
index 90d9275..cc3a6b6 100644
--- a/time.c
+++ b/time.c
@@ -41,7 +41,9 @@ static ID id_nanosecond, id_microsecond, id_millisecond, id_nsec, id_usec;
static ID id_local_to_utc, id_utc_to_local;
static ID id_year, id_mon, id_mday, id_hour, id_min, id_sec, id_isdst, id_name;
-#define TM_IS_TIME 1
+#ifndef TM_IS_TIME
+#define TM_IS_TIME 0
+#endif
#define NDIV(x,y) (-(-((x)+1)/(y))-1)
#define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)
@@ -5127,6 +5129,34 @@ tm_to_time(VALUE tm)
#endif
}
+#if !TM_IS_TIME
+static VALUE
+tm_zero(VALUE tm)
+{
+ return INT2FIX(0);
+}
+
+#define tm_subsec tm_zero
+#define tm_utc_offset tm_zero
+
+static VALUE
+tm_isdst(VALUE tm)
+{
+ return Qfalse;
+}
+
+static VALUE
+tm_to_s(VALUE tm)
+{
+ const VALUE *p = RSTRUCT_CONST_PTR(tm);
+
+ return rb_sprintf("%.4"PRIsVALUE"-%.2"PRIsVALUE"-%.2"PRIsVALUE" "
+ "%.2"PRIsVALUE":%.2"PRIsVALUE":%.2"PRIsVALUE" "
+ "UTC",
+ p[5], p[4], p[3], p[2], p[1], p[0]);
+}
+#endif
+
VALUE
rb_time_zone_abbreviation(VALUE zone, VALUE time)
{
@@ -5285,9 +5315,13 @@ Init_Time(void)
rb_cTimeTM = rb_struct_define_under(rb_cTime, "TM",
"sec", "min", "hour",
"mday", "mon", "year",
- "subsec", "isdst",
"to_i", NULL);
- rb_alias(rb_cTimeTM, rb_intern("dst?"), id_isdst);
+ rb_define_method(rb_cTimeTM, "subsec", tm_subsec, 0);
+ rb_define_method(rb_cTimeTM, "utc_offset", tm_utc_offset, 0);
+ rb_define_method(rb_cTimeTM, "to_s", tm_to_s, 0);
+ rb_define_method(rb_cTimeTM, "inspect", tm_to_s, 0);
+ rb_define_method(rb_cTimeTM, "isdst", tm_isdst, 0);
+ rb_define_method(rb_cTimeTM, "dst?", tm_isdst, 0);
#endif
rb_define_method(rb_cTimeTM, "initialize", tm_initialize, -1);
rb_define_method(rb_cTimeTM, "utc", tm_to_time, 0);