Skip to content

Commit

Permalink
Support AfricArXiv preprints with only a year-month posted date
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Nov 7, 2024
1 parent 5ec0c84 commit 73926e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/DatacitePreprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface DatacitePreprint {
readonly abstract: string
readonly authors: ReadonlyArray<string>
readonly doi: Doi.Doi
readonly posted: Temporal.PlainDate
readonly posted: Temporal.PlainDate | Temporal.PlainYearMonth
readonly server: 'africarxiv' | 'arxiv'
readonly title: string
}
Expand Down Expand Up @@ -87,9 +87,7 @@ export const getPreprintFromDatacite = (
Match.when(Match.instanceOfUnsafe(Temporal.PlainYear), () =>
Either.left(new GetPreprintFromDataciteError({ message: 'Published date incomplete' })),
),
Match.when(Match.instanceOfUnsafe(Temporal.PlainYearMonth), () =>
Either.left(new GetPreprintFromDataciteError({ message: 'Published date incomplete' })),
),
Match.when(Match.instanceOfUnsafe(Temporal.PlainYearMonth), date => Either.right(date)),
Match.exhaustive,
),
),
Expand Down
13 changes: 11 additions & 2 deletions src/ReviewRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,17 @@ function formatList(list: ReadonlyArray<string>) {
return formatter.format(list)
}

function renderDate(date: Temporal.PlainDate) {
return date.toLocaleString('en', { dateStyle: 'long' })
function renderDate(date: Temporal.PlainDate | Temporal.PlainYearMonth) {
return pipe(
Match.value(date),
Match.when({ [Symbol.toStringTag]: 'Temporal.PlainYearMonth' }, date =>
date.toLocaleString('en', { calendar: date.calendarId, month: 'long', year: 'numeric' }),
),
Match.when({ [Symbol.toStringTag]: 'Temporal.PlainDate' }, date =>
date.toLocaleString('en', { dateStyle: 'long' }),
),
Match.exhaustive,
)
}

const postMessageOnSlack = flow(
Expand Down
4 changes: 2 additions & 2 deletions test/DataCitePreprint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('getPreprintFromDatacite', () => {
),
fc.string(),
fc.string(),
fc.plainDate(),
fc.oneof(fc.plainYearMonth(), fc.plainDate()),
fc.constantFrom('Submitted', 'Created', 'Issued'),
])('when a work is found', (doi, [expectedDoi, expectedServer], expectedTitle, abstract, posted, dateType) =>
Effect.gen(function* ($) {
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('getPreprintFromDatacite', () => {
fc.dataciteWork({
dates: fc.nonEmptyArray(
fc.record({
date: fc.oneof(fc.plainYear(), fc.plainYearMonth()),
date: fc.plainYear(),
dateType: fc.constant('Submitted'),
}),
),
Expand Down

0 comments on commit 73926e5

Please sign in to comment.