Class: Strptime

Inherits:
Object
  • Object
show all
Defined in:
lib/strptime.rb,
lib/strptime/version.rb,
ext/strptime/strptime.c

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#new(format) ⇒ Object

returns parser object



636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'ext/strptime/strptime.c', line 636

static VALUE
strptime_init(VALUE self, VALUE fmt)
{
    struct strptime_object *tobj;
    void **isns;
    StringValue(fmt);
    TypedData_Get_Struct(self, struct strptime_object, &strptime_data_type,
       tobj);
    isns = strptime_compile(RSTRING_PTR(fmt), RSTRING_LEN(fmt));
    tobj->isns = isns;
    tobj->fmt = rb_str_new_frozen(fmt);
    return self;
}

Instance Method Details

#exec(str) ⇒ Time

Returns:

  • (Time)


696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'ext/strptime/strptime.c', line 696

static VALUE
strptime_exec(VALUE self, VALUE str)
{
    struct strptime_object *tobj;
    int r, gmtoff = 0;
    StringValue(str);
    GetStrptimeval(self, tobj);
    struct timespec ts;

    r = strptime_exec0(tobj->isns, RSTRING_PTR(tobj->fmt), RSTRING_PTR(str),
           RSTRING_LEN(str), &ts, &gmtoff);
    if (r) rb_raise(rb_eArgError, "string doesn't match");
    return rbtime_timespec_new(&ts, gmtoff);
}

#execi(str) ⇒ Integer

returns epoch as integer

Returns:

  • (Integer)


717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'ext/strptime/strptime.c', line 717

static VALUE
strptime_execi(VALUE self, VALUE str)
{
    struct strptime_object *tobj;
    struct timespec ts;
    int r, gmtoff = 0;
    StringValue(str);
    GetStrptimeval(self, tobj);

    r = strptime_exec0(tobj->isns, RSTRING_PTR(tobj->fmt), RSTRING_PTR(str),
           RSTRING_LEN(str), &ts, &gmtoff);
    if (r) rb_raise(rb_eArgError, "string doesn't match");
    return TIMET2NUM(ts.tv_sec);
}

#initialize_copy(self) ⇒ Object

:nodoc:



651
652
653
654
655
656
657
658
659
660
661
662
# File 'ext/strptime/strptime.c', line 651

static VALUE
strptime_init_copy(VALUE copy, VALUE self)
{
    struct strptime_object *tobj, *tcopy;

    if (!OBJ_INIT_COPY(copy, self)) return copy;
    GetStrptimeval(self, tobj);
    GetNewStrptimeval(copy, tcopy);
    MEMCPY(tcopy, tobj, struct strptime_object, 1);

    return copy;
}

#sourceString

returns source format string

Returns:

  • (String)


738
739
740
741
742
743
744
745
# File 'ext/strptime/strptime.c', line 738

static VALUE
strptime_source(VALUE self)
{
    struct strptime_object *tobj;
    GetStrptimeval(self, tobj);

    return tobj->fmt;
}