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

Fix Discrepancy for publicationYear #303

Merged
merged 6 commits into from
Jan 29, 2024
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
3 changes: 2 additions & 1 deletion src/components/FormComponents/ApaPreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function generateCitation(record, language, format) {
created,
contacts = [],
datePublished,
dateRevised,
} = record;

const publishers = contacts
Expand Down Expand Up @@ -46,7 +47,7 @@ export function generateCitation(record, language, format) {
// seems that only individuals gets cited? Wasnt sure how to get organization name in there
return { family: contact.orgName };
}),
issued: { "date-parts": [[datePublished || created]] },
issued: { "date-parts": [[dateRevised || datePublished || created]] },
publisher: publishers.join(", "),
DOI: datasetIdentifier.replace(/https?:\/\/doi\.org\//, ""),
version: `v${record.edition}`,
Expand Down
3 changes: 2 additions & 1 deletion src/components/FormComponents/DateInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ function formatDate(date) {
const m = date.getMonth();
const y = date.getFullYear();
// This is to get around the issue of timezones and dates
return new Date(y, m, d, 12, 0, 0, 0);
return (new Date(y, m, d, 12, 0, 0, 0)).toISOString();
} catch (e) {
return null;
}
}

const DateInput = ({ onChange, value, name, disabled, dateStart, dateEnd }) => {
return (
<MuiPickersUtilsProvider utils={DateFnsUtils}>
Expand Down
15 changes: 12 additions & 3 deletions src/components/__tests__/DateInput.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jest.spyOn(global, "Date").mockImplementation(() => mockedData);
Date.now = () => 1606348800;

configure({ adapter: new Adapter() });
const mockEventValue = new Date("2021-09-08T22:23:52.468Z");

// Use an ISO string for the mock event value
const mockEventValue = "2021-09-08T22:23:52.468Z";
const mockComponentName = "date";
const mockOnChange = jest.fn();

Expand All @@ -33,9 +35,16 @@ describe("<DateInput />", () => {
/>
);

wrapper.find(KeyboardDatePicker).props().onChange(mockEventValue);
// Simulate selecting a new date as a Date object
const newDate = new Date("2021-10-08T22:23:52.468Z");
wrapper.find(KeyboardDatePicker).props().onChange(newDate);

// The expected value should be an ISO string after being processed by your component
const expectedValue = newDate.toISOString();

// Assert that onChange was called with the correct value
expect(mockOnChange).toHaveBeenCalledWith({
target: { value: mockEventValue, name: mockComponentName },
target: { value: expectedValue, name: mockComponentName },
});
});
});
11 changes: 7 additions & 4 deletions src/utils/recordToDataCite.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ function recordToDataCite(metadata, language, region) {
contact.role.includes("publisher")
);

// Get the publication year from the datePublished field
// Get the publication year from the datePublished field, if dateRevised contains value use dateRevised as publication year
let publicationYear;
if (metadata.datePublished) {
const year = parseInt(metadata.datePublished.slice(0, 4), 10)
publicationYear = Number.isNaN(year) ? undefined : year;
if (metadata.dateRevised) {
const revisedYear = parseInt(metadata.dateRevised.slice(0, 4), 10);
publicationYear = Number.isNaN(revisedYear) ? undefined : revisedYear;
} else if (metadata.datePublished) {
const publishedYear = parseInt(metadata.datePublished.slice(0, 4), 10)
publicationYear = Number.isNaN(publishedYear) ? undefined : publishedYear;
} else {
publicationYear = undefined;
}
Expand Down
Loading