Skip to content
New issue

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

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

Already on GitHub? # to your account

[candidate] Allow dob format Y-m #8648

Merged
Merged
Changes from 2 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
13 changes: 12 additions & 1 deletion php/libraries/Candidate.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,25 @@ class Candidate implements \LORIS\StudyEntities\AccessibleResource,
DOB_NOT_SPECIFIED
);
}
$dob = DateTime::createFromFormat('!Y-m-d', $dateOfBirth);

// Get expected format from config
$dobFormat = $config->getSetting('dobFormat');
$dobFormat = '!' . implode("-", str_split($dobFormat, 1));
$dob = DateTime::createFromFormat($dobFormat, $dateOfBirth);

if ($dob === false) {
throw new InvalidArgumentException(
"Date of Birth is invalid (expected format: YYYY-MM-DD)",
DOB_INVALID
);
}

// Add day as first of the month if Y-m dob format
// This allows insert into sql candidate table
if ($dobFormat === '!Y-m') {
$dateOfBirth .= '-01';
}

if ($PSCIDSettings['generation'] == 'user') {
// check pscid is specified
if (empty($PSCID)) {
Expand Down