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 */
} 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);
["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"]=>
["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"]=>
--- /dev/null
+--TEST--
+ion\serialize/timestamp
+--EXTENSIONS--
+ion
+--FILE--
+TEST
+<?php
+$dt = ion\unserialize("1971-02-03T04:05:06.789Z");
+var_dump($dt);
+$ts = ion\serialize($dt);
+var_dump($ts);
+
+var_dump(ion\unserialize($ts));
+?>
+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