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

Allow EDTF date to refine basic date with time #220

Merged
merged 1 commit into from
Aug 6, 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
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
Loading