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

[LINST] Remove '_date' only for Standard Format #6923

Merged
Merged
Show file tree
Hide file tree
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
25 changes: 17 additions & 8 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 All @@ -583,7 +576,9 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
// Set date format
$dateFormat = isset($pieces[5]) ? trim($pieces[5]) : "";

if (isset($dateFormat) && $dateFormat != "") {
if (isset($dateFormat) && $dateFormat != ""
&& $dateFormat !== "Date"
) {
if ($dateFormat === 'MonthYear') {
// Shows date without day of month
$this->addMonthYear(
Expand All @@ -600,6 +595,20 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
);
}
} else {
// addDateElement appends '_date' to the field name so
// remove it first here
if (substr($pieces[1], -5) == "_date") {
$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