Skip to content

Commit

Permalink
removing _date should only happen for standard format
Browse files Browse the repository at this point in the history
php lint

travis
  • Loading branch information
zaliqarosli committed Nov 23, 2020
1 parent 4621058 commit cb1f676
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 14 additions & 7 deletions php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
$this->LinstQuestions[$pieces[1]] = ['type' => 'textarea'];
break;
case 'date':
if (strpos($pieces[1], "_date") !== false) {
$pieces[1] = substr(
$pieces[1],
0,
strpos($pieces[1], "_date")
);
}
if ($addElements) {
if ($pieces[3] == 1900 && $pieces[4] == 2100) {
$dateOptions = null;
Expand Down Expand Up @@ -600,6 +593,20 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
);
}
} else {
// addDateElement appends '_date' to the field name so
// remove it first here
if (strpos($pieces[1], "_date") !== false) {
$pieces[1] = substr(
$pieces[1],
0,
strpos($pieces[1], "_date")
);
} else {
throw new \LorisException(
"Standard Date format field $pieces[1] must end"
. " with '_date'."
);
}
// Shows standard date
$this->addDateElement(
$pieces[1],
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/NDB_BVL_Instrument_LINST_ToJSON_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function testAllElements()
. "'option_1'=>'Option 1'{-}'option_2'=>'Option 2'{-}"
. "'option_3'=>'Option 3'{-}'option_4'=>'Option 4'{-}"
. "'not_answered'=>'Not Answered'\n";
$instrument .= "date{@}FieldName{@}Field Description{@}2003{@}2014\n";
$instrument .= "date{@}FieldName_date{@}Field Description{@}2003{@}2014\n";
$instrument .= "select{@}date_status{@}{@}NULL=>''{-}"
. "'not_answered'=>'Not Answered'\n";
$instrument .= "numeric{@}FieldName{@}Field Description{@}0{@}20\n";
Expand Down Expand Up @@ -250,7 +250,7 @@ function testAllElements()
],
[
'Type' => "date",
"Name" => "FieldName",
"Name" => "FieldName_date",
"Description" => "Field Description",
"Options" => [
"MinDate" => "2003-01-01",
Expand Down

0 comments on commit cb1f676

Please # to comment.