Skip to content

Commit 61a40a7

Browse files
authored
Merge pull request #4 from joshdentremont/2.x
Fixed bug around issued dates being YYYY-MM
2 parents f28b62a + 184cfe6 commit 61a40a7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Utility/DataciteDOITrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,17 @@ protected function buildMetadataRequest(array $data) {
249249
if (array_key_exists("datacite.dateIssued", $data)) {
250250
$di = str_replace('X', '0', $data["datacite.dateIssued"][0]["value"]);
251251
$years = array();
252+
// If the date is not a standard date in the form YYYY-MM-DD, just pull the year
252253
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $data["datacite.year"][0]["value"])) {
253254
preg_match('/\b[\dX]{4}\b/', $di, $years);
254255
$di = $years[0];
255256
}
256257

257-
$date = $dates->addChild('date', $di)->addAttribute('dateType', 'Issued');
258+
$date = $dates->addChild('date', $di);
259+
$date->addAttribute('dateType', 'Issued');
260+
// If our stored date differs from the original, put the original in the dateInformation attribute
258261
if ($di !== $data["datacite.dateIssued"][0]["value"])
259-
$date->addAttribute('dateInformation', $data["datacite.dateIssued"]);
262+
$date->addAttribute('dateInformation', $data["datacite.dateIssued"][0]["value"]);
260263
}
261264

262265
// Language.

0 commit comments

Comments
 (0)