You are here

function date_year_digit_check in Date 6.2

Same name and namespace in other branches
  1. 5.2 date_php4/date_php4.inc \date_year_digit_check()
  2. 6 date_php4/date_php4.inc \date_year_digit_check()

Fix 2-digit years. Works for any century. Assumes that if 2-digit is more than 30 years in future, then previous century.

1 call to date_year_digit_check()
_date_mktime in date_php4/date_php4_lib.inc
Low level function to create mktime() for pre-1970 and post 2038 dates.

File

date_php4/date_php4.inc, line 994

Code

function date_year_digit_check($y) {
  if ($y < 100) {
    $yr = (int) date("Y");
    $century = (int) ($yr / 100);
    if ($yr % 100 > 50) {
      $c1 = $century + 1;
      $c0 = $century;
    }
    else {
      $c1 = $century;
      $c0 = $century - 1;
    }
    $c1 *= 100;

    // if 2-digit year is less than 30 years in future, set it to this century
    // otherwise if more than 30 years in future, then we set 2-digit year to the prev century.
    if ($y + $c1 < $yr + 30) {
      $y = $y + $c1;
    }
    else {
      $y = $y + $c0 * 100;
    }
  }
  return $y;
}