Class: Time (Ruby 2.4.2)
Description: Class : Time - Ruby 2.4.2

Support for the Ruby 2.4 series has ended. See here for reference.

### Home Classes Methods

### In Files

- date/date_core.c

### Parent

Object

### Methods

- #to_date
- #to_datetime
- #to_time

### Class/Module Index

Quicksearch

- Date
- DateTime
- Time

No matching classes.

# Time

### Public Instance Methods

to_date → date click to toggle source

Returns a `Date` object which denotes self.

                   static VALUE
    time_to_date(VALUE self)
    {
        VALUE y, nth, ret;
        int ry, m, d;

        y = f_year(self);
        m = FIX2INT(f_mon(self));
        d = FIX2INT(f_mday(self));

        decode_year(y, -1, &nth, &ry);

        ret = d_simple_new_internal(cDate,
                                    nth, 0,
                                    GREGORIAN,
                                    ry, m, d,
                                    HAVE_CIVIL);
        {
            get_d1(ret);
            set_sg(dat, DEFAULT_SG);
        }
        return ret;
    }

to_datetime → datetime click to toggle source

Returns a `DateTime` object which denotes self.

                   static VALUE
    time_to_datetime(VALUE self)
    {
        VALUE y, sf, nth, ret;
        int ry, m, d, h, min, s, of;

        y = f_year(self);
        m = FIX2INT(f_mon(self));
        d = FIX2INT(f_mday(self));

        h = FIX2INT(f_hour(self));
        min = FIX2INT(f_min(self));
        s = FIX2INT(f_sec(self));
        if (s == 60)
            s = 59;

        sf = sec_to_ns(f_subsec(self));
        of = FIX2INT(f_utc_offset(self));

        decode_year(y, -1, &nth, &ry);

        ret = d_complex_new_internal(cDateTime,
                                     nth, 0,
                                     0, sf,
                                     of, DEFAULT_SG,
                                     ry, m, d,
                                     h, min, s,
                                     HAVE_CIVIL | HAVE_TIME);
        {
            get_d1(ret);
            set_sg(dat, DEFAULT_SG);
        }
        return ret;
    }

to_time → time click to toggle source

Returns self.

                   static VALUE
    time_to_time(VALUE self)
    {
        return self;
    }