Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#to_date ⇒ Object
to_date() -> Date.
-
#to_datetime ⇒ Object
to_datetime() -> DateTime.
-
#to_time ⇒ Object
to_time() -> Time.
Instance Method Details
#to_date ⇒ Object
to_date() -> Date
Returns a Date
with the same year, month, and day as the receiver in local time.
Time.local(2009, 1, 2).to_date
# => #<Date 2009-01-02>
3495 3496 3497 3498 3499 3500 3501 3502 3503 |
# File 'ext/date_ext/date_ext.c', line 3495 static VALUE rhrd_time_to_date(VALUE self) { rhrd_t *d; VALUE rd; rd = Data_Make_Struct(rhrd_class, rhrd_t, NULL, -1, d); d->jd = rhrd__unix_to_jd(NUM2LONG(rb_funcall(self, rhrd_id_to_i, 0)) + NUM2LONG(rb_funcall(self, rhrd_id_utc_offset, 0))); d->flags = RHR_HAVE_JD; RHR_CHECK_JD(d) return rd; } |
#to_datetime ⇒ Object
to_datetime() -> DateTime
Returns a DateTime
with the same year, month, day, hour, minute, and second as the receiver in local time.
Time.local(2009, 1, 2, 12).to_datetime
# => #<DateTime 2009-01-02T12:00:00-08:00>
2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 |
# File 'ext/date_ext/datetime.c', line 2630 static VALUE rhrdt_time_to_datetime(VALUE self) { rhrdt_t *dt; VALUE rd; long t, offset; rd = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, dt); offset = NUM2LONG(rb_funcall(self, rhrd_id_utc_offset, 0)); t = NUM2LONG(rb_funcall(self, rhrd_id_to_i, 0)) + offset; dt->jd = rhrd__unix_to_jd(t); #ifdef RUBY19 dt->nanos = rhrd__mod(t, RHR_SECONDS_PER_DAY) * RHR_NANOS_PER_SECOND + NUM2LONG(rb_funcall(self, rhrd_id_nsec, 0)); #else dt->nanos = rhrd__mod(t, RHR_SECONDS_PER_DAY) * RHR_NANOS_PER_SECOND + NUM2LONG(rb_funcall(self, rhrd_id_usec, 0)) * 1000; #endif dt->offset = (short)(offset/60); dt->flags |= RHR_HAVE_JD | RHR_HAVE_NANOS; RHR_CHECK_JD(dt); return rd; } |
#to_time ⇒ Object
to_time() -> Time
Returns a copy of the receiver in local time.
Time.local(2009, 1, 2).to_time
# => 2009-01-02 00:00:00 -0800
Time.local(2009, 1, 2).getutc.to_time
# => 2009-01-02 00:00:00 -0800
3516 3517 3518 |
# File 'ext/date_ext/date_ext.c', line 3516 static VALUE rhrd_time_to_time(VALUE self) { return rb_funcall(self, rhrd_id_getlocal, 0); } |