You are here

function _date_mktime in Date 5.2

Same name and namespace in other branches
  1. 6.2 date_php4/date_php4_lib.inc \_date_mktime()
  2. 6 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:

$timezone name: Use 'UTC' to avoid timezone conversion.

1 call to _date_mktime()
date_mktime in date_php4/date_php4.inc
Return a timestamp given a local time.

File

date_php4/date_php4_lib.inc, line 352

Code

function _date_mktime($hr, $min, $sec, $mon = false, $day = false, $year = false, $timezone = false) {
  if ($timezone === FALSE) {
    $timezone = date_default_timezone_name();
  }

  /*
  # 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 - 1) / 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) {
    $year_in = $year;
    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;
    $ret -= date_get_gmt_diff_ts($ret, $timezone);
  }
  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);
    if ($ret < -12220185600) {
      $ret += 10 * 86400;
    }
    else {
      if ($ret < -12219321600) {
        $ret = -12219321600;
      }
    }

    // if in limbo, reset to 15 Oct 1582.
  }
  return $ret;
}