Skip to content

Commit

Permalink
Merge pull request #22 from Language-Research-Technology/datePublishe…
Browse files Browse the repository at this point in the history
…d_validation

for #21
  • Loading branch information
alvinsw authored Nov 1, 2024
2 parents 146f1c8 + 1779950 commit 232174e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
38 changes: 20 additions & 18 deletions lib/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,24 +381,26 @@ class Validator {
let id = "datePublishedFormat"
let clause = `datePublished: MUST be a string in [ISO 8601 date format][DateTime] and SHOULD be specified to at least the precision of a day, MAY be a timestamp down to the millisecond.`
if (root?.datePublished) {
if (!root.datePublished[0].match(/^\d{4}-?([0]\d|1[0-2])?-?([0-2]\d|3[01])?/)) {
this.log(
{
id,
status: "error",
message: `datePublished does not start with a compliant date in this format: YYYY, YYYY-MM or YYYY-MM-DD`,
clause
}
);
} else {
this.log(
{
id,
status: "success",
message: "datePublished is in compliant format.",
clause
}
);
for(let dP of root.datePublished) {
if (dP && !dP.match(/^\d{4}-?([0]\d|1[0-2])?-?([0-2]\d|3[01])?/)) {
this.log(
{
id,
status: "error",
message: `datePublished does not start with a compliant date in this format: YYYY, YYYY-MM or YYYY-MM-DD`,
clause
}
);
} else {
this.log(
{
id,
status: "success",
message: "datePublished is in compliant format.",
clause
}
);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ro-crate",
"version": "3.4.1",
"version": "3.4.2",
"description": "Research Object Crate (RO-Crate) utilities for making and consuming crates",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 232174e

Please sign in to comment.