From: Michael Wallner Date: Mon, 10 Jan 2022 14:13:32 +0000 (+0100) Subject: tests: fix fractional timestamps X-Git-Tag: v0.1.0~40 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f5be992c9f4fc0de9f0a43194bda962bc4c738b0;p=awesomized%2Fext-ion tests: fix fractional timestamps --- diff --git a/ion_private.h b/ion_private.h index 205c9b8..600f18b 100644 --- a/ion_private.h +++ b/ion_private.h @@ -929,10 +929,10 @@ LOCAL ION_TIMESTAMP *ion_timestamp_from_php(ION_TIMESTAMP *buf, php_ion_timestam zval tmp; int precision = Z_LVAL_P(zend_read_property(ts->std.ce, &ts->std, ZEND_STRL("precision"), 0, &tmp)); - if (!precision || precision > ION_TS_FRAC) { + if (!precision || precision > (ION_TS_FRAC|0x80)) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, IERR_INVALID_ARG, "Invalid precision (%d) of ion\\Timestamp", precision); - } else switch ((buf->precision = precision)) { + } else switch ((buf->precision = precision) & 0x7f) { case ION_TS_FRAC: ion_ts_frac_from_usec(&buf->fraction, (int) ts->time->us, ctx); /* fallthrough */ diff --git a/tests/Timestamp.phpt b/tests/Timestamp.phpt index 1b4a222..c0f0171 100644 --- a/tests/Timestamp.phpt +++ b/tests/Timestamp.phpt @@ -14,7 +14,7 @@ try { } catch (Throwable) { echo "caught empty\n"; } -$full = "2021-12-07T14:08:51+00:00"; +$full = "2021-12-07T14:08:51.123456+00:00"; var_dump($t=new Timestamp(Timestamp\Precision::Day, datetime:$full),(string)$t); var_dump($t=new Timestamp(Timestamp\Precision::Day->value, datetime:$full),(string)$t); var_dump($t=new Timestamp(Timestamp\Precision::Min, datetime:"2020-10-01"),(string)$t); @@ -32,7 +32,7 @@ object(ion\Timestamp)#%d (5) { ["format"]=> string(7) "Y-m-d\T" ["date"]=> - string(26) "2021-12-07 14:08:51.000000" + string(26) "2021-12-07 14:08:51.123456" ["timezone_type"]=> int(1) ["timezone"]=> @@ -45,7 +45,7 @@ object(ion\Timestamp)#%d (5) { ["format"]=> string(7) "Y-m-d\T" ["date"]=> - string(26) "2021-12-07 14:08:51.000000" + string(26) "2021-12-07 14:08:51.123456" ["timezone_type"]=> int(1) ["timezone"]=> diff --git a/tests/serialize/timestamp.phpt b/tests/serialize/timestamp.phpt new file mode 100644 index 0000000..21941af --- /dev/null +++ b/tests/serialize/timestamp.phpt @@ -0,0 +1,35 @@ +--TEST-- +ion\serialize/timestamp +--EXTENSIONS-- +ion +--FILE-- +TEST + +DONE +--EXPECTF-- +TEST +object(ion\Timestamp)#5 (3) { + ["precision"]=> + int(247) + ["format"]=> + string(1) "c" + ["date"]=> + string(26) "1971-02-03 04:05:06.789000" +} +string(24) "1971-02-03T04:05:06.789Z" +object(ion\Timestamp)#6 (3) { + ["precision"]=> + int(247) + ["format"]=> + string(1) "c" + ["date"]=> + string(26) "1971-02-03 04:05:06.789000" +} +DONE