From:             rjones-php-ibase-bug at ico dot viva dot org
Operating system: windows 2000 and Linux
PHP version:      4.3.6
PHP Bug Type:     InterBase related
Bug description:  ibase_fetch_row returns inconsistent formats for TIMESTAMP fields on 
firebird

Description:
------------
This function does not work consistently on Linux and Windows 2000 with
dates with small years.

The strings it returns are
under Linux: "01/01/1"
under Windows: "01/01/0001"

I have traced this back:
        ibase_fetch_row -> _php_ibase_fetch_hash -> _php_ibase_var_zval ->
strftime

in interbase.c at line 1919:

#if HAVE_STRFTIME
                                Z_STRLEN_P(val) = strftime(string_data, 
sizeof(string_data), format,
&t);
#else
                                /* FIXME */
                                if (!t.tm_hour && !t.tm_min && !t.tm_sec) {
                                        Z_STRLEN_P(val) = sprintf(string_data, 
"%02d/%02d/%4d", t.tm_mon + 1,
t.tm_mday, t.tm_year + 1900);
                                } else {
                                        Z_STRLEN_P(val) = sprintf(string_data, 
"%02d/%02d/%4d
%02d:%02d:%02d", t.tm_mon+1, t.tm_mday, t.tm_year + 1900, t.tm_hour,
t.tm_min, t.tm_sec);
                                }
#endif

As a work-around, I've used 

#if HAVE_STRFTIME
// Make this consistent with PHP on windows.
// FixMe This should give consistent results for all years from 0001
onwards
                                if(t.tm_year < 10)      
                                {
                                        if (!t.tm_hour && !t.tm_min && !t.tm_sec) {
                                                Z_STRLEN_P(val) = sprintf(string_data, 
"%02d/%02d/000%d", t.tm_mon +
1, t.tm_mday, t.tm_year+1900);
                                        } else {
                                                Z_STRLEN_P(val) = sprintf(string_data, 
"%02d/%02d/000%d
%02d:%02d:%02d", t.tm_mon+1, t.tm_mday, t.tm_year+1900, t.tm_hour,
t.tm_min, t.tm_sec);
                                        }
                                }
                                else
                                {
                                        Z_STRLEN_P(val) = strftime(string_data, 
sizeof(string_data), format,
&t);
                                }
#else
                                /* FIXME */
                                if (!t.tm_hour && !t.tm_min && !t.tm_sec) {
                                        Z_STRLEN_P(val) = sprintf(string_data, 
"%02d/%02d/%4d", t.tm_mon + 1,
t.tm_mday, t.tm_year + 1900);
                                } else {
                                        Z_STRLEN_P(val) = sprintf(string_data, 
"%02d/%02d/%4d
%02d:%02d:%02d", t.tm_mon+1, t.tm_mday, t.tm_year + 1900, t.tm_hour,
t.tm_min, t.tm_sec);
                                }
#endif


Reproduce code:
---------------
$rs_temp=ibase_query("SELECT time_stamp_field FROM
some_stored_procedure()"); 
$row_temp=ibase_fetch_row($rs_temp);
print($row_temp[0]); 

Expected result:
----------------
01/01/0001

Actual result:
--------------
01/01/1

-- 
Edit bug report at http://bugs.php.net/?id=28543&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28543&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28543&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28543&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28543&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28543&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28543&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28543&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28543&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28543&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28543&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28543&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28543&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28543&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28543&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28543&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28543&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28543&r=float

Reply via email to