In Files

  • time.c

Parent

Class/Module Index [+]

Quicksearch

Time::TM

A container class for timezone conversion.

Public Class Methods

Time::TM.from_time(t) → tm click to toggle source

Creates new Time::TM object from a Time object.

 
               static VALUE
tm_from_time(VALUE klass, VALUE time)
{
    struct time_object *tobj;
    struct vtm vtm, *v;
#ifdef TM_IS_TIME
    VALUE tm;
    struct time_object *ttm;

    GetTimeval(time, tobj);
    tm = time_s_alloc(klass);
    ttm = DATA_PTR(tm);
    v = &vtm;
    GMTIMEW(ttm->timew = tobj->timew, v);
    v->subsecx = INT2FIX(0);
    v->zone = Qnil;
    ttm->vtm = *v;
    ttm->tm_got = 1;
    TZMODE_SET_UTC(ttm);
    return tm;
#else
    VALUE args[8];
    int i = 0;

    GetTimeval(time, tobj);
    if (tobj->tm_got && TZMODE_UTC_P(tobj))
        v = &tobj->vtm;
    else
        GMTIMEW(tobj->timew, v = &vtm);
    args[i++] = v->year;
    args[i++] = INT2FIX(v->mon);
    args[i++] = INT2FIX(v->mday);
    args[i++] = INT2FIX(v->hour);
    args[i++] = INT2FIX(v->min);
    args[i++] = INT2FIX(v->sec);
    switch (v->isdst) {
      case 0: args[i++] = Qfalse; break;
      case 1: args[i++] = Qtrue; break;
      default: args[i++] = Qnil; break;
    }
    args[i++] = w2v(rb_time_unmagnify(tobj->timew));
    return rb_class_new_instance(i, args, klass);
#endif
}
            
Time::TM.new(year, month, day, hour, min, sec) → tm click to toggle source

Creates new Time::TM object.

 
               static VALUE
tm_initialize(int argc, VALUE *argv, VALUE tm)
{
#ifdef TM_IS_TIME
    struct time_object *tobj = DATA_PTR(tm);
    struct vtm vtm;

    rb_check_arity(argc, 6, 6);
    time_arg(argc, argv, &vtm);
    tobj->tzmode = TIME_TZMODE_UTC;
    tobj->timew = timegmw(&vtm);
    tobj->vtm = vtm;
    return tm;
#else
    int i = 0;
    struct vtm vtm;
    wideval_t t;

    time_arg(argc, argv, &vtm);
    t = timegmw(&vtm);
    RSTRUCT_SET(tm, i++, INT2FIX(vtm.sec));
    RSTRUCT_SET(tm, i++, INT2FIX(vtm.min));
    RSTRUCT_SET(tm, i++, INT2FIX(vtm.hour));
    RSTRUCT_SET(tm, i++, INT2FIX(vtm.mday));
    RSTRUCT_SET(tm, i++, INT2FIX(vtm.mon));
    RSTRUCT_SET(tm, i++, vtm.year);
    RSTRUCT_SET(tm, i++, INT2FIX(0));
    switch (vtm.isdst) {
      case 0: RSTRUCT_SET(tm, i++, Qfalse); break;
      case 1: RSTRUCT_SET(tm, i++, Qtrue); break;
      default: RSTRUCT_SET(tm, i++, Qnil); break;
    }
    RSTRUCT_SET(tm, i++, w2v(rb_time_unmagnify(t)));
    return tm;
#endif
}
            

Public Instance Methods

to_time → time click to toggle source

Returns a new Time object.

 
               static VALUE
tm_to_time(VALUE tm)
{
#ifdef TM_IS_TIME
    struct time_object *torig = get_timeval(tm);
    VALUE dup = time_s_alloc(rb_cTime);
    struct time_object *tobj = DATA_PTR(dup);
    *tobj = *torig;
    return dup;
#else
    VALUE t[6];
    const VALUE *p = RSTRUCT_CONST_PTR(tm);
    int i;

    for (i = 0; i < numberof(t); ++i) {
        t[i] = p[numberof(t) - 1 - i];
    }
    return time_s_mkutc(numberof(t), t, rb_cTime);
#endif
}