Class: JapaneseDateFormat
- Inherits:
-
Object
- Object
- JapaneseDateFormat
- Defined in:
- ext/jadtfmt.c
Constant Summary collapse
- VERSION =
rb_str_new2(VERSION)
Instance Method Summary collapse
Instance Method Details
#apply_pattern(pattern) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'ext/jadtfmt.c', line 120
static VALUE jadtfmt_apply_pattern(VALUE self, VALUE pattern) {
struct jadtfmt *p;
Check_Type(pattern, T_STRING);
Data_Get_Struct(self, struct jadtfmt, p);
jadtfmt_icu_apply_pattern(p->fmt, StringValuePtr(pattern), p->codepage);
p->pattern_len = RSTRING(pattern)->len;
return Qnil;
}
|
#format(src) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'ext/jadtfmt.c', line 65
static VALUE jadtfmt_format(VALUE self, VALUE src) {
struct jadtfmt *p;
VALUE year, month, day, hour, min, sec;
char *buf;
if (!rb_obj_is_instance_of(src, rb_cTime)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Time)", rb_class2name(CLASS_OF(src)));
}
year = rb_funcall(src, rb_intern("year"), 0);
month = rb_funcall(src, rb_intern("month"), 0);
day = rb_funcall(src, rb_intern("day"), 0);
hour = rb_funcall(src, rb_intern("hour"), 0);
min = rb_funcall(src, rb_intern("min"), 0);
sec = rb_funcall(src, rb_intern("sec"), 0);
Data_Get_Struct(self, struct jadtfmt, p);
if (p->pattern_len > 0) {
int len = p->pattern_len * 3 + 16;
buf = alloca(len);
memset(buf, 0, len);
} else {
rb_raise(rb_eRuntimeError, "pattern is not set");
}
jadtfmt_icu_format(p->fmt, NUM2INT(year), NUM2INT(month), NUM2INT(day), NUM2INT(hour), NUM2INT(min), NUM2INT(sec), p->codepage, buf);
return rb_str_new2(buf);
}
|
#format_attrs(*args) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'ext/jadtfmt.c', line 97
static VALUE jadtfmt_format_attrs(int argc, VALUE *argv, VALUE self) {
struct jadtfmt *p;
VALUE year, month, day, hour, min, sec;
char *buf;
rb_scan_args(argc, argv, "15", &year, &month, &day, &hour, &min, &sec);
Data_Get_Struct(self, struct jadtfmt, p);
if (p->pattern_len > 0) {
int len = p->pattern_len * 3 + 16;
buf = alloca(len);
memset(buf, 0, len);
} else {
rb_raise(rb_eRuntimeError, "pattern is not set");
}
jadtfmt_icu_format(p->fmt, NUM2INT(year), DEFAULT_INT(month), DEFAULT_INT(day), DEFAULT_INT(hour), DEFAULT_INT(min), DEFAULT_INT(sec), p->codepage, buf);
return rb_str_new2(buf);
}
|