Skip to content

Commit

Permalink
Fixed issue #15310: Display dropdown boxes - Date/Time question type …
Browse files Browse the repository at this point in the history
…not working correctly if minimum date < 1900 (#3353)

Co-authored-by: Lapiu Dev <devgit@lapiu.biz>
  • Loading branch information
gabrieljenik and lapiudevgit committed Sep 15, 2023
1 parent 5bc3d5f commit 9a6265a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions application/core/QuestionTypes/Date/RenderDate.php
Expand Up @@ -83,7 +83,7 @@ public function setMinDate()
$date_min = trim((string) $this->getQuestionAttribute('date_min'));
$date_time_em = strtotime((string) LimeExpressionManager::ProcessString("{" . $date_min . "}", $this->oQuestion->qid));

if (ctype_digit($date_min) && (strlen($date_min) == 4) && ($date_min >= 1900) && ($date_min <= 2099)) {
if (ctype_digit($date_min) && (strlen($date_min) == 4)) {
$this->minDate = $date_min . '-01-01'; // backward compatibility: if only a year is given, add month and day
} elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $date_min)) {
// it's a YYYY-MM-DD date (use http://www.yiiframework.com/doc/api/1.1/CDateValidator ?)
Expand All @@ -105,7 +105,7 @@ public function setMaxDate()
$date_max = trim((string) $this->getQuestionAttribute('date_max'));
$date_time_em = strtotime((string) LimeExpressionManager::ProcessString("{" . $date_max . "}", $this->oQuestion->qid));

if (ctype_digit($date_max) && (strlen($date_max) == 4) && ($date_max >= 1900) && ($date_max <= 2099)) {
if (ctype_digit($date_max) && (strlen($date_max) == 4)) {
$this->maxDate = $date_max . '-12-31'; // backward compatibility: if only a year is given, add month and day
} elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $date_max)) {
// it's a YYYY-MM-DD date (use http://www.yiiframework.com/doc/api/1.1/CDateValidator ?)
Expand Down Expand Up @@ -152,13 +152,13 @@ private function getYearSelect($iCurrent)
* expressions are not supported because contents of dropbox cannot be easily updated dynamically
*/
$yearmin = (int) substr((string) $this->minDate, 0, 4);
if (!isset($yearmin) || $yearmin < 1900 || $yearmin > 2187) {
if (empty($yearmin)) {
$yearmin = 1900;
}

$yearmax = (int) substr((string) $this->maxDate, 0, 4);
if (!isset($yearmax) || $yearmax < 1900 || $yearmax > 2187) {
$yearmax = 2187;
if (empty($yearmax)) {
$yearmax = 2037;
}

if ($yearmin > $yearmax) {
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -1569,7 +1569,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq = null)
// date_min: Determine whether we have an expression, a full date (YYYY-MM-DD) or only a year(YYYY)
if (trim((string) $qattr['date_min']) != '') {
$mindate = $qattr['date_min'];
if ((strlen((string) $mindate) == 4) && ($mindate >= 1900) && ($mindate <= 2099)) {
if ((strlen((string)$mindate) == 4)) {
// backward compatibility: if only a year is given, add month and day
$date_min = '\'' . $mindate . '-01-01' . ' 00:00\'';
} elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", (string) $mindate)) {
Expand Down Expand Up @@ -1627,7 +1627,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq = null)
// date_max: Determine whether we have an expression, a full date (YYYY-MM-DD) or only a year(YYYY)
if (trim((string) $qattr['date_max']) != '') {
$maxdate = $qattr['date_max'];
if ((strlen((string) $maxdate) == 4) && ($maxdate >= 1900) && ($maxdate <= 2099)) {
if ((strlen((string)$maxdate) == 4)) {
// backward compatibility: if only a year is given, add month and day
$date_max = '\'' . $maxdate . '-12-31 23:59' . '\'';
} elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", (string) $maxdate)) {
Expand Down

0 comments on commit 9a6265a

Please sign in to comment.