function _date_mktime in Date 6
Same name and namespace in other branches
- 5.2 date_php4/date_php4_lib.inc \_date_mktime()
- 6.2 date_php4/date_php4_lib.inc \_date_mktime()
Low level function to create mktime() for pre-1970 and post 2038 dates.
Parameters
$hr the hour:
$min the minute:
$sec the second:
$mon the month:
$day the day:
$year the year:
$test whether the date functions are being test, used to force the: low level function even for current dates.
1 call to _date_mktime()
- date_mktime in date_php4/
date_php4.inc - Return a timestamp given a local time. Originally by jackbbs.
File
- date_php4/
date_php4_lib.inc, line 343
Code
function _date_mktime($hr, $min, $sec, $mon = false, $day = false, $year = false, $is_gmt = false, $test = false) {
$gmt_different = $is_gmt ? 0 : date_get_gmt_diff();
/*
# disabled because some people place large values in $sec.
# however we need it for $mon because we use an array...
$hr = intval($hr);
$min = intval($min);
$sec = intval($sec);
*/
$mon = intval($mon);
$day = intval($day);
$year = intval($year);
$year = date_year_digit_check($year);
if ($mon > 12) {
$y = floor($mon / 12);
$year += $y;
$mon -= $y * 12;
}
else {
if ($mon < 1) {
$y = ceil((1 - $mon) / 12);
$year -= $y;
$mon += $y * 12;
}
}
$_day_power = 86400;
$_hour_power = 3600;
$_min_power = 60;
$_month_table_normal = array(
"",
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31,
);
$_month_table_leap = array(
"",
31,
29,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31,
);
$_total_date = 0;
if ($year >= 1970) {
for ($a = 1970; $a <= $year; $a++) {
$leap = date_is_leap_year($a);
if ($leap == true) {
$loop_table = $_month_table_leap;
$_add_date = 366;
}
else {
$loop_table = $_month_table_normal;
$_add_date = 365;
}
if ($a < $year) {
$_total_date += $_add_date;
}
else {
for ($b = 1; $b < $mon; $b++) {
$_total_date += $loop_table[$b];
}
}
}
$_total_date += $day - 1;
$ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different;
}
else {
for ($a = 1969; $a >= $year; $a--) {
$leap = date_is_leap_year($a);
if ($leap == true) {
$loop_table = $_month_table_leap;
$_add_date = 366;
}
else {
$loop_table = $_month_table_normal;
$_add_date = 365;
}
if ($a > $year) {
$_total_date += $_add_date;
}
else {
for ($b = 12; $b > $mon; $b--) {
$_total_date += $loop_table[$b];
}
}
}
$_total_date += $loop_table[$mon] - $day;
$_day_time = $hr * $_hour_power + $min * $_min_power + $sec;
$_day_time = $_day_power - $_day_time;
$ret = -($_total_date * $_day_power + $_day_time - $gmt_different);
if ($ret < -12220185600) {
$ret += 10 * 86400;
}
else {
if ($ret < -12219321600) {
$ret = -12219321600;
}
}
// if in limbo, reset to 15 Oct 1582.
}
return $ret;
}