php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71062 pg_convert() doesn't accept ISO 8601 for datatype timestamp
Submitted: 2015-12-08 14:19 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: denver at timothy dot io Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: 7.0.0 OS: Mac OS 10.11.1
Private report: No CVE-ID: None
 [2015-12-08 14:19 UTC] denver at timothy dot io
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


Patches

pg_convert_fix_iso_8601 (last revision 2015-12-08 14:20 UTC by denver at timothy dot io)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-15 11:42 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d263616525450026bc36b263d2777fd092cf432b
Log: Fixed #71062 pg_convert() doesn't accept ISO 8601 for datatype timestamp
 [2016-04-15 11:42 UTC] ab@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d263616525450026bc36b263d2777fd092cf432b
Log: Fixed #71062 pg_convert() doesn't accept ISO 8601 for datatype timestamp
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC