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 +4 -4
- data/ext/teptris_ext/materialize.c +22 -13
- data/lib/teptris/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eb7e2d637c9a7d99cf511aa513c6b107bf53ae3338057466f52c8b86ed94da79
|
|
4
|
+
data.tar.gz: 8bd5fe1d88f86a95ea4b9711bf53ef1bfb41793fe922865928b720e9a57bec49
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
25
|
-
* Time.local with Rational seconds (
|
|
26
|
-
*
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
/*
|
|
210
|
-
*
|
|
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 = (
|
|
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)
|
|
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
|
}
|
data/lib/teptris/version.rb
CHANGED