Skip to content
Open
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
20 changes: 10 additions & 10 deletions src/js/models/metadata/eml211/EMLTemporalCoverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,18 @@ define([
}
},

validateTimeFormat: function (timeString) {
//If the last character is a "Z", then remove it for now
if (
timeString.substring(timeString.length - 1, timeString.length) == "Z"
) {
timeString = timeString.replace("Z", "", "g");
}
validateTimeFormat(time) {
// xs:time allows fractional seconds and a time zone designator
// (Z, +hh:mm or -hh:mm), so remove them before checking HH:MM:SS
const timeString = time.replace(
/(\.\d+)?(Z|[+-](?:(?:0\d|1[0-3]):[0-5]\d|14:00))?$/,
"",
);

if (timeString.length == 8) {
var timeParts = timeString.split(":");
if (timeString.length === 8) {
const timeParts = timeString.split(":");

if (timeParts.length != 3) {
if (timeParts.length !== 3) {
return "Time must be formatted as HH:MM:SS";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,44 @@ define([
expect(m.isValid()).to.equal(false);
});
});

describe("validating times", function () {
it("should accept times with a time zone designator", function () {
var m = new EMLTemporalCoverage();
expect(m.validateTimeFormat("11:50:00-09:00")).to.equal(true);
expect(m.validateTimeFormat("14:06:09+08:00")).to.equal(true);
expect(m.validateTimeFormat("08:31:22Z")).to.equal(true);
expect(m.validateTimeFormat("11:50:00+14:00")).to.equal(true);
expect(m.validateTimeFormat("24:00:00-09:00")).to.equal(true);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hour 24 should only allow a zero fraction (along with 0 minutes and 0 seconds). This adds a failing case and checks that a zero fraction is still accepted:

Suggested change
it("should require zero fractional seconds when the hour is 24", function () {
var m = new EMLTemporalCoverage();
expect(m.validateTimeFormat("24:00:00.1")).to.be.a("string");
expect(m.validateTimeFormat("24:00:00.000Z")).to.equal(true);
});

it("should accept times with fractional seconds", function () {
var m = new EMLTemporalCoverage();
expect(m.validateTimeFormat("11:50:00.5")).to.equal(true);
expect(m.validateTimeFormat("11:50:00.123Z")).to.equal(true);
expect(m.validateTimeFormat("11:50:00.5-09:00")).to.equal(true);
});

it("should reject malformed time zone designators", function () {
var m = new EMLTemporalCoverage();
expect(m.validateTimeFormat("11:50:00-9:00")).to.be.a("string");
expect(m.validateTimeFormat("11:50:00-09")).to.be.a("string");
expect(m.validateTimeFormat("11:50:00-15:00")).to.be.a("string");
expect(m.validateTimeFormat("11:50:00x09:00")).to.be.a("string");
expect(m.validateTimeFormat("11:50:00.Z")).to.be.a("string");
expect(m.validateTimeFormat("24:30:00-09:00")).to.be.a("string");
});

it("should be valid when a parsed time has a time zone designator", function () {
var m = new EMLTemporalCoverage({
objectDOM: $(
"<temporalcoverage><singledatetime><calendardate>2020</calendardate><time>11:50:00-09:00</time></singledatetime></temporalcoverage>",
).get(0),
});

expect(m.get("beginTime")).to.equal("11:50:00-09:00");
expect(m.isValid()).to.equal(true);
});
});
});
});