Bug #71062 [NEW]: pg_convert() doesn't accept ISO 8601 for datatype timestamp
From: denver at timothy dot io
Operating system: Mac OS 10.11.1
PHP version: 7.0.0
Package: PostgreSQL related
Bug Type: Bug
Bug description:pg_convert() doesn't accept ISO 8601 for datatype timestamp
Description:
------------
pg_convert() does not accept an ISO 8601 date/time string, but will if
the character "T" is replaced with whitespace. This is inconsistent with
the constant DateTime::ISO8601 and date("c").
I believe if the regex in pgsql.c for case PG_TIMESTAMP (line 6165) can
be improved (see patch).
Test script:
---------------
$db = pg_connect("dbname=test user=test");
pg_query($db, "CREATE TABLE public.test_table ( test_field TIMESTAMPTZ
)");
// ISO 8601 (with 'T' between date and time)
$date_string_php_iso8601 = date_create('8 Dec 2015
5:38')->format(DateTime::ISO8601);
// ISO 8601 with the 'T' removed
$modified_format = 'Y-m-d H:i:sO';
$date_string_modified_iso8601 = date_create('8 Dec 2015
5:38')->format($modified_format);
printf("trying format %s \n", DateTime::ISO8601);
pg_convert($db, 'public.test_table', ['test_field' =>
$date_string_php_iso8601]);
printf("trying format %s \n", $modified_format);
pg_convert($db, 'public.test_table', ['test_field' =>
$date_string_modified_iso8601]);
print "done\n";
pg_query($db, "DROP TABLE test_table");
Expected result:
----------------
trying format Y-m-d\TH:i:sO
trying format Y-m-d H:i:sO
done
Actual result:
--------------
trying format Y-m-d\TH:i:sO
PHP Notice: pg_convert(): Expects NULL or string for PostgreSQL
timestamptz field (test_field) in /Users/dlt/Desktop/bug.php on line 16
Notice: pg_convert(): Expects NULL or string for PostgreSQL timestamptz
field (test_field) in /Users/dlt/Desktop/bug.php on line 16
trying format Y-m-d H:i:sO
done
--
Edit bug report at https://bugs.php.net/bug.php?id=71062&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71062&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71062&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71062&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71062&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71062&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71062&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71062&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71062&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71062&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71062&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71062&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71062&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71062&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71062&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71062&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71062&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71062&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71062&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71062&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71062&r=mysqlcfg
Thread (2 messages)
- denver at timothy dot io