[PHP-DEV] Bug #994: gmmktime() doesn't return proper data From: bam <email protected>
Date: 12/17/98

From: bam <email protected>
Operating system: Linux 2.x
PHP version: 3.0.4
PHP Bug Type: Misbehaving function
Bug description: gmmktime() doesn't return proper data

Under glibc Linux, gmmktime() and mktime() return the same value given the same arguments, even in time zones where there should be an offset.

I believe the source of the problem is in functions/datetime.c:_php3_mktime(). In this function, the following code is relevant to this problem:

-----
        if (gm) {
                tn = gmtime(&t);
#if HAVE_TZSET
                tzset();
#if HAVE_TM_ZONE
                gmadjust=(tn->tm_gmtoff)/3600;
#else
                gmadjust=timezone/3600;
#endif
#endif
-----

HAVE_TZSET and HAVE_TM_ZONE are both defined by configure for glibc Linux systems. I think the above code assumes that gmtime() will set t.tm_gmtoff -- but it doesn't set or alter its value. So (tn->tm_gmtoff)/3600 ends up being 0, and no time zone adjustment is made. The net effect is that gmmktime() appears to work just like mktime() on this platform (I have no idea if this affects others).

Here is a script that can reproduce the problem:

-----
<?php
$secs = date( "U" );
$datestr = date( "H i s m d Y", $secs );

echo "The current time is $datestr <BR>";

list( $hr, $mi, $se, $mo, $da, $yr ) = split( " ", $datestr );

echo "Calling that local time, it's "
        . date( "U", mktime( $hr, $mi, $se, $mo, $da, $yr ) )
        . " seconds since the epoch <BR>";

echo "Calling that UTC, it's "
        . date( "U", gmmktime( $hr, $mi, $se, $mo, $da, $yr ) )
        . " seconds since the epoch <BR>";
?>
-----

The last two echo statements should return different values, different by the appropriate time zone offset. For me, they return the exact same number.

My configure line:

./configure --with-mysql=/usr/local/mysql --with-apache=/config/local/cvs/apache-cvs/apache-1.3

I confirmed that this code path doesn't work as expected on
- RedHat Linux 5.1, kernel 2.0.35, glibc 2.0.7
- Debian Linux "slink", kernel 2.1.131, glibc 2.0.7
- Debian Linux "slink", kernel 2.0.36, glibc 2.0.7

Thanks in advance for your attention.

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>