teptris 0.2.46 → 0.2.47

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
  SHA256:
3
- metadata.gz: af75c2b1cc5b2fa3d12c1d743b35630c81044bf3e9755a2b15b76b2229a9d14e
4
- data.tar.gz: a47fc895fee5679a2f30edeb0c3387925d7c8725610a632cdaed9acd8e88fd37
3
+ metadata.gz: eb7e2d637c9a7d99cf511aa513c6b107bf53ae3338057466f52c8b86ed94da79
4
+ data.tar.gz: 8bd5fe1d88f86a95ea4b9711bf53ef1bfb41793fe922865928b720e9a57bec49
5
5
  SHA512:
6
- metadata.gz: 2d8c34ce3367858c05e0ef721da0c96467b4ef7d9afad2c05e5b891a4bcc991412ba90af534626508eac94c705e7b58803abc252bdb6585fae0ae9a6e3fa20aa
7
- data.tar.gz: 985dc7ce2dceb16cd5e3857015d890b8df8e138f75b9dca4abd860896a8f626c51fcfc6633aab7631c1402d2b4b17baf2fc2cab020e15b56bf6587069886a1b7
6
+ metadata.gz: 9ea8e593b8dbdb13bc4e47b0de51f9417ece4947519ef6f6206a8e56efe381f7cabe59a726a22592bf30822e100be15ebcfec9c1288b13ddb86a351799b8949b
7
+ data.tar.gz: d2b11be087c63609aa8e993efb4f9fcea8ad879adcc78e47c6ea19193bdd9b23f3e98e8b97f11ac631bbe52ed364b273c09ec301727a284393e75fe6d7aa137a
@@ -21,18 +21,25 @@ static int64_t days_from_civil(int32_t y, uint8_t m, uint8_t d) {
21
21
  }
22
22
 
23
23
  /* exact (no double) Time materialization: nsec stays nsec. Offset
24
- * datetimes go through timespec+fixed-offset; local datetimes through
25
- * Time.local with Rational seconds (rb_time_timespec_new's INT_MAX
26
- * treats the timespec as an absolute instant, not wall-clock local). */
24
+ * datetimes carry a fixed utc offset via rb_time_num_new; local
25
+ * datetimes go through Time.local with Rational seconds (both treat
26
+ * the epoch value as wall-clock for locals / instant+offset for
27
+ * fixed zones). No struct timespec crosses the Ruby boundary:
28
+ * armhf glibc rubies build with _TIME_BITS=64 (16-byte timespec)
29
+ * while an ext compiled without it lays out 8 bytes — the struct
30
+ * APIs then read (load) or write (dump) past each side's layout. */
27
31
  static VALUE time_from_dt(const teptris_datetime *d, bool has_offset) {
28
32
  if (has_offset) {
29
33
  int64_t days = days_from_civil(d->year, d->month, d->day);
30
34
  int64_t secs =
31
35
  days * 86400 + d->hour * 3600 + d->minute * 60 + d->second;
32
- struct timespec ts;
33
- ts.tv_sec = (time_t)(secs - d->offset_seconds);
34
- ts.tv_nsec = (long)d->nanosecond;
35
- return rb_time_timespec_new(&ts, d->offset_seconds);
36
+ VALUE num = LL2NUM(secs - d->offset_seconds);
37
+ if (d->nanosecond != 0) {
38
+ num = rb_funcall(num, '+', 1,
39
+ rb_Rational(LL2NUM((int64_t)d->nanosecond),
40
+ LL2NUM(1000000000)));
41
+ }
42
+ return rb_time_num_new(num, INT2FIX(d->offset_seconds));
36
43
  }
37
44
  VALUE args[6] = {INT2FIX(d->year), INT2FIX(d->month), INT2FIX(d->day),
38
45
  INT2FIX(d->hour), INT2FIX(d->minute),
@@ -180,7 +187,7 @@ static VALUE ext_version(VALUE self) {
180
187
 
181
188
  /* ------------------------------------------------------------------ dump */
182
189
 
183
- static ID id_utc_offset, id_to_s;
190
+ static ID id_utc_offset, id_to_s, id_to_i, id_nsec;
184
191
 
185
192
  static void dump_check(teptris_status st) {
186
193
  if (st == TEPTRIS_OK) return;
@@ -206,12 +213,12 @@ static void civil_from_days(int64_t z, int32_t *y, uint8_t *m, uint8_t *d) {
206
213
  *d = (uint8_t)dd;
207
214
  }
208
215
 
209
- /* two crossings per Time: timespec + utc_offset; the civil fields come
210
- * from integer math (epoch + offset -> y/m/d h:m:s + tv_nsec) */
216
+ /* the instant and its subsecond part come back as Integers (to_i
217
+ * floors, nsec stays in [0, 1e9) — same split the timespec gave);
218
+ * the civil fields are integer math on epoch + offset */
211
219
  static void fill_dt_from_time(VALUE v, teptris_datetime *dt) {
212
- struct timespec ts = rb_time_timespec(v);
213
220
  dt->offset_seconds = NUM2INT(rb_funcall(v, id_utc_offset, 0));
214
- int64_t secs = (int64_t)ts.tv_sec + dt->offset_seconds;
221
+ int64_t secs = NUM2LL(rb_funcall(v, id_to_i, 0)) + dt->offset_seconds;
215
222
  int64_t days = secs / 86400;
216
223
  int32_t rem = (int32_t)(secs % 86400);
217
224
  if (rem < 0) { /* floor division: keep rem in [0, 86400) */
@@ -222,7 +229,7 @@ static void fill_dt_from_time(VALUE v, teptris_datetime *dt) {
222
229
  dt->hour = (uint8_t)(rem / 3600);
223
230
  dt->minute = (uint8_t)((rem / 60) % 60);
224
231
  dt->second = (uint8_t)(rem % 60);
225
- dt->nanosecond = (uint32_t)ts.tv_nsec;
232
+ dt->nanosecond = (uint32_t)NUM2LL(rb_funcall(v, id_nsec, 0));
226
233
  }
227
234
 
228
235
  static void dump_scalar(teptris_builder *b, const char *key, size_t klen,
@@ -967,4 +974,6 @@ void Init_teptris_ext(void) {
967
974
  cDate = rb_const_get(rb_cObject, rb_intern("Date"));
968
975
  id_utc_offset = rb_intern("utc_offset");
969
976
  id_to_s = rb_intern("to_s");
977
+ id_to_i = rb_intern("to_i");
978
+ id_nsec = rb_intern("nsec");
970
979
  }
@@ -1,3 +1,3 @@
1
1
  module Teptris
2
- VERSION = "0.2.46"
2
+ VERSION = "0.2.47"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.46
4
+ version: 0.2.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - teptris contributors