Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rolling window for translating 2-digit years into 4-digit years #22581

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions CRM/Utils/Date.php
Original file line number Diff line number Diff line change
@@ -540,8 +540,6 @@ public static function isoToMysql($iso) {
*/
public static function convertToDefaultDate(&$params, $dateType, $dateParam) {
$now = getdate();
$cen = substr($now['year'], 0, 2);
$prevCen = $cen - 1;

$value = NULL;
if (!empty($params[$dateParam])) {
@@ -693,15 +691,15 @@ public static function convertToDefaultDate(&$params, $dateType, $dateParam) {
$month = ($month < 10) ? "0" . "$month" : $month;
$day = ($day < 10) ? "0" . "$day" : $day;

$year = (int ) $year;
// simple heuristic to determine what century to use
// 00 - 20 is always 2000 - 2020
// 21 - 99 is always 1921 - 1999
if ($year < 21) {
$year = (strlen($year) == 1) ? $cen . '0' . $year : $cen . $year;
}
elseif ($year < 100) {
$year = $prevCen . $year;
$year = (int) $year;
if ($year < 100) {
$year = substr($now['year'], 0, 2) * 100 + $year;
if ($year > ($now['year'] + 5)) {
$year = $year - 100;
}
elseif ($year <= ($now['year'] - 95)) {
$year = $year + 100;
}
}

if ($params[$dateParam]) {