strptime 0.2.0.beta2 → 0.2.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc1df53ebcd9f15ddf913c586ce3580cebe192a9
4
- data.tar.gz: 1ec52362be465e23ad6226c6048e876075e3564c
3
+ metadata.gz: 5888a6c2d53ab4cc5a55654bb8322cbefed4cd5e
4
+ data.tar.gz: d46348be35b99abe4b4fd90bf7f4b555598d6131
5
5
  SHA512:
6
- metadata.gz: 75b6df02855bb0488d0a42147210949814c3be497a91532cbe9adbd53560ef2c984afa5d4ffcaf7266b5c90c6fcfebcbc493e428690260f09a3fb9c80f4b5f5e
7
- data.tar.gz: 3a03b9299174c34007491cc0ab98a7906e0841ef93b309786b1cc72fd4347a88c8719c704abd6805339c72bc1f3391ce32405d8ffb62905079eacf614a0ebbb9
6
+ metadata.gz: b751a50b7a9a78ee862f1cd461fb3dc0e5ea1d5eb7e9a2ec18d783d94ee6b13cea9504c01987e0bd63543e471d8619c30718a434134d5d70d018c98ed6b13397
7
+ data.tar.gz: 96e23338cb997b45315a6dbaafd544c8d0045b6d9d1846398809fc889856668ae98844766f97905564085dfd449993a834a2c1f810007496414b4d0596353494
@@ -2,5 +2,6 @@ require "mkmf"
2
2
 
3
3
  have_func('rb_timespec_now')
4
4
  have_func('rb_time_timespec_new')
5
+ have_func('rb_time_utc_offset')
5
6
 
6
7
  create_makefile("strptime/strptime")
@@ -3,6 +3,9 @@
3
3
  #include <time.h>
4
4
 
5
5
  VALUE rb_cStrftime;
6
+ #ifndef HAVE_RB_TIME_UTC_OFFSET
7
+ static ID id_gmtoff;
8
+ #endif
6
9
 
7
10
  #define GetStrftimeval(obj, tobj) ((tobj) = get_strftimeval(obj))
8
11
  #define GetNewStrftimeval(obj, tobj) ((tobj) = get_new_strftimeval(obj))
@@ -65,7 +68,7 @@ strftime_exec0(void **pc, VALUE fmt, struct timespec *tsp, int gmtoff, size_t re
65
68
  LABEL_PTR(m), NULL, NULL, NULL,
66
69
  NULL, NULL, NULL, NULL,
67
70
  NULL, NULL, NULL, NULL,
68
- LABEL_PTR(y), NULL,
71
+ LABEL_PTR(y), LABEL_PTR(z),
69
72
  };
70
73
  *pc = (void *)insns_address_table;
71
74
  return Qnil;
@@ -163,6 +166,26 @@ strftime_exec0(void **pc, VALUE fmt, struct timespec *tsp, int gmtoff, size_t re
163
166
  ADD_PC(1);
164
167
  END_INSN(y)
165
168
  }
169
+ INSN_ENTRY(z)
170
+ {
171
+ int h, m, tmp=gmtoff;
172
+ if (gmtoff >= 0) {
173
+ *p++ = '+';
174
+ } else {
175
+ *p++ = '-';
176
+ tmp = -tmp;
177
+ }
178
+ tmp /= 60;
179
+ h = (tmp / 60)&15; /* ignore too large offset */
180
+ m = tmp % 60;
181
+ *p++ = '0' + (h / 10);
182
+ *p++ = '0' + (h % 10);
183
+ *p++ = ':';
184
+ *p++ = '0' + (m / 10);
185
+ *p++ = '0' + (m % 10);
186
+ ADD_PC(1);
187
+ END_INSN(y)
188
+ }
166
189
  INSN_ENTRY(_60)
167
190
  {
168
191
  size_t v = (size_t)GET_OPERAND(1);
@@ -233,6 +256,10 @@ strftime_compile(const char *fmt, size_t flen, size_t *rlenp)
233
256
  goto accept_format;
234
257
  case 'y':
235
258
  rlen += 2;
259
+ goto accept_format;
260
+ case 'z':
261
+ rlen += 6;
262
+ goto accept_format;
236
263
  accept_format:
237
264
  tmp = insns_address_table[c - 'A'];
238
265
  if (tmp) {
@@ -388,11 +415,16 @@ strftime_init_copy(VALUE copy, VALUE self)
388
415
  static VALUE
389
416
  strftime_exec(VALUE self, VALUE time)
390
417
  {
391
- struct strftime_object *tobj;
418
+ struct strftime_object *sobj;
392
419
  struct timespec ts = rb_time_timespec(time);
393
- GetStrftimeval(self, tobj);
420
+ #ifdef HAVE_RB_TIME_UTC_OFFSET
421
+ int gmtoff = FIX2INT(rb_time_utc_offset(time));
422
+ #else
423
+ int gmtoff = NUM2INT(rb_funcall(time, id_gmtoff, 0));
424
+ #endif
425
+ GetStrftimeval(self, sobj);
394
426
 
395
- return strftime_exec0(tobj->isns, tobj->fmt, &ts, 0, tobj->result_length);
427
+ return strftime_exec0(sobj->isns, sobj->fmt, &ts, gmtoff, sobj->result_length);
396
428
  }
397
429
 
398
430
  /*
@@ -459,4 +491,5 @@ Init_strftime(void)
459
491
  rb_define_method(rb_cStrftime, "exec", strftime_exec, 1);
460
492
  rb_define_method(rb_cStrftime, "execi", strftime_execi, 1);
461
493
  rb_define_method(rb_cStrftime, "source", strftime_source, 0);
494
+ id_gmtoff = rb_intern("gmtoff");
462
495
  }
@@ -1,3 +1,3 @@
1
1
  class Strptime
2
- VERSION = "0.2.0.beta2"
2
+ VERSION = "0.2.0.beta3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strptime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.beta2
4
+ version: 0.2.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - NARUSE, Yui
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-24 00:00:00.000000000 Z
11
+ date: 2017-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler