Class: Late
- Inherits:
-
Object
- Object
- Late
- Defined in:
- lib/late.rb,
lib/late/version.rb,
ext/late/late.c
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
-
.epoch ⇒ Object
our new native method; it just returns the seconds since epoch“.
-
.httpdate(rb_epoch) ⇒ Object
Outputs Tue, 05 Mar 2013 16:58:29 GMT.
- .pp(rb_epoch, rb_format) ⇒ Object
Class Method Details
.epoch ⇒ Object
our new native method; it just returns the seconds since epoch“
26 27 28 29 |
# File 'ext/late/late.c', line 26 static VALUE late_epoch(VALUE self) { time_t current_time = time(NULL); return INT2FIX(current_time); } |
.httpdate(rb_epoch) ⇒ Object
Outputs Tue, 05 Mar 2013 16:58:29 GMT
5 6 7 8 9 10 11 12 |
# File 'ext/late/late.c', line 5
const VALUE late_httpdate(VALUE self, VALUE rb_epoch) {
time_t epoch = FIX2LONG(rb_epoch);
struct tm * timeinfo;
char buffer[80];
timeinfo = gmtime(&epoch);
strftime(buffer, 80, "%a, %d %b %Y %H:%M:%S GMT", timeinfo);
return rb_str_new2(buffer);
}
|
.pp(rb_epoch, rb_format) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'ext/late/late.c', line 14
const VALUE late_pp(VALUE self, VALUE rb_epoch, VALUE rb_format) {
time_t epoch = FIX2LONG(rb_epoch);
char * format = RSTRING_PTR(rb_format);
struct tm * timeinfo = gmtime(&epoch);
int buffer_length = RSTRING_LEN(rb_format) + 40;
char buffer[buffer_length];
timeinfo = gmtime(&epoch);
strftime(buffer, buffer_length, format, timeinfo);
return rb_str_new2(buffer);
}
|