note 49954 added to function.gmmktime
| From: | (AT) | Date: | Sun, 13 Feb 2005 18:04:19 +0000 |
| Subject: | note 49954 added to function.gmmktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84931@lists.php.net to get a copy of this message | ||
I have seen many different hacked versions of this function for people using Windows that want to
support dates before Jan 1, 1970. Here is yet another one that is different than others you may have
seen! It does not use loops like all the others I have seen!
<?
// usage...
echo win_gmmktime ( 12, 43, 16, 07, 23, 1946 );
function win_gmmktime ( $hour, $minute, $second, $month, $day, $year )
{
if ( $year > 1969 )
{
return ( gmmktime ( $hour, $minute, $second, $month, $day, $year ) );
}
$t = 0;
$ds = 86400;
$hs = 3600;
$dy = 365;
$ms = 60;
$months = array ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
$leap_year = $year % 4 == 0 && ( $year % 100 > 0 || $year % 400 == 0 ) ? true : false;
if ( $year < 1969 )
{
$y = 1969 - $year;
$t -= ( $y * $dy ) * $ds;
$x = ceil ( $y / 4 );
if ( $leap_year && $month > 2 )
{
$x -= 1;
}
$t -= $x * $ds;
}
if ( $month != 12 )
{
$tm = $months;
$tm = array_slice ( $tm, $month );
$t -= array_sum ( $tm ) * $ds;
unset ( $tm );
}
$nh = ( ( $month == 2 && $leap_year ? 29 : $months[$month-1] ) - $day );
$t -= $nh != 0 ? $nh * $ds : 0;
$nh = 23 - $hour;
$t -= $nh != 0 ? $nh * $hs : 0;
$nh = 59 - $minute;
$t -= $nh != 0 ? $nh * $ms : 0;
$nh = 59 - $second;
$t -= $nh != 0 ? $nh + 1 : 0;
return ( $t );
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.gmmktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49954
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49954&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49954&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49954&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49954&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49954&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49954&report=yes
Search -- http://master.php.net/manage/user-notes.php