Skip to content

Commit

Permalink
Allow EDTF date to refine basic date with time
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Jun 15, 2024
1 parent a5a46ae commit 6097ab1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/validations/mismatched_dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ export function validationMismatchedDates() {

function validateEDTF(key, msgKey) {
if (!entity.tags[key] || !entity.tags[key + ':edtf']) return;
let basic = parseEDTF(entity.tags[key]);
let basic = entity.tags[key];
// start_date and end_date disallow time precision. Transform the basic date into a daylong range in EDTF to allow a comparison to an EDTF date with time precision.
// https://github.com/OpenHistoricalMap/issues/issues/764
if (basic.match('^-?[0-9]+-[0-9]{2}-[0-9]{2}$')) {
basic = `${basic}T00:00:00/${basic}T24:00:00`;
}
let basicAsEDTF = parseEDTF(basic);
let parsed = parseEDTF(entity.tags[key + ':edtf']);
if (!basic || !parsed || parsed.covers(basic)) return;
if (!basicAsEDTF || !parsed || parsed.covers(basicAsEDTF) || basicAsEDTF.covers(parsed)) return;

issues.push(new validationIssue({
type: type,
Expand Down
12 changes: 12 additions & 0 deletions test/spec/validations/mismatched_dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ describe('iD.validations.mismatched_dates', function () {
expect(issue.entityIds[0]).to.eql('n-1');
});

it('ignores way with date narrowed by EDTF time range', function() {
createNode({ shop: 'mall', name: 'Forest Fair Mall', start_date: '1988-07-11', 'start_date:edtf': '1988-07-11T10:00', end_date: '2003-06-10', 'end_date:edtf': '2003-06-10T08:00/2003-06-10T21:00' });
let issues = validate();
expect(issues).to.have.lengthOf(0);
});

it('flags way with date outside of EDTF time range', function() {
createNode({ shop: 'mall', name: 'Forest Fair Mall', start_date: '1988-07-11', 'start_date:edtf': '1988-07-12', end_date: '2003-06-11', 'end_date:edtf': '2003-06-10T08:00/2003-06-10T21:00' });
let issues = validate();
expect(issues).to.have.lengthOf(2);
});

it('equates unknown date with unspecified date in EDTF extended interval', function() {
let validator = iD.validationMismatchedDates(context);
expect(validator.parseEDTF('/1234').toString()).to.equal(validator.parseEDTF('../1234').toString());
Expand Down

0 comments on commit 6097ab1

Please sign in to comment.