Bug #71062 [Opn->Csd]: pg_convert() doesn't accept ISO 8601 for datatype timestamp

From: Date: Fri, 15 Apr 2016 11:42:31 +0000
Subject: Bug #71062 [Opn->Csd]: pg_convert() doesn't accept ISO 8601 for datatype timestamp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200565@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71062&edit=1

 ID:                 71062
 Updated by:         ab@php.net
 Reported by:        denver at timothy dot io
 Summary:            pg_convert() doesn't accept ISO 8601 for datatype
                     timestamp
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            PostgreSQL related
 Operating System:   Mac OS 10.11.1
 PHP Version:        7.0.0
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2015-12-08 14:19:52] 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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71062&edit=1


Thread (2 messages)

« previous php.bugs (#200565) next »