You are here

function date_mktime in Date 6.2

Same name and namespace in other branches
  1. 5.2 date_php4/date_php4.inc \date_mktime()
  2. 5 date.inc \date_mktime()
  3. 6 date_php4/date_php4.inc \date_mktime()

Return a timestamp given a local time.

Parameters

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

Force anything that will require timezone conversion to use lower level functions to make sure we adjust to the right timezone (native 'date' functions use the server timezone).

2 calls to date_mktime()
date_datetime2timestamp in date_php4/date_php4.inc
Create a timestamp from a datetime value.
date_gmmktime in date_php4/date_php4.inc
Like date_mktime with no GMT conversion.

File

date_php4/date_php4.inc, line 936

Code

function date_mktime($hr, $min, $sec, $mon = FALSE, $day = FALSE, $year = FALSE, $timezone = FALSE) {
  if ($timezone === FALSE) {
    $timezone = date_default_timezone_name();
  }
  $is_gmt = $timezone == 'UTC' ? TRUE : FALSE;
  $hr = intval($hr);
  $min = intval($min);
  $sec = intval($sec);
  if ($mon === FALSE && $is_gmt) {
    return @gmmktime($hr, $min, $sec);
  }
  $mon = intval($mon) > 0 ? intval($mon) : date('n');
  $day = intval($day) > 0 ? intval($day) : date('j');
  $year = intval($year) > 0 ? intval($year) : date('Y');

  // Don't use native handling for any values that could create negative
  // timestamp, Windows does not support them at all in PHP 4, and
  // the adodb date library notes that since RedHat 7.3, negative
  // timestamps are not supported in glibc either.
  // Step in one year on either side of allowable 1970-2038 window
  // to be sure timezone adjustments and month and day additions
  // won't push our date outside this window.
  if (1971 < $year && $year < 2037 && $is_gmt) {
    return @gmmktime($hr, $min, $sec, $mon, $day, $year);
  }
  return _date_mktime($hr, $min, $sec, $mon, $day, $year, $timezone);
}