Skip to content

Commit

Permalink
bug: patch odata datetime output to account for collect omitting mins.
Browse files Browse the repository at this point in the history
* ISO requires tz to always be fully specified if provided; eg +07:00
* but javarosa/collect sometimes does just eg +07 alone
* so now we have to sniff that out and patch it.
  • Loading branch information
issa-tseng committed Feb 12, 2019
1 parent e14bd03 commit 8c18677
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/data/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ const submissionToOData = (fields, table, submission, options = {}) => new Promi
dataPtr[name] = `POINT (${coordinates.join(' ')})`;
else // geojson is the default:
dataPtr[name] = { type: 'Point', coordinates };
} else if (type === 'dateTime') {
// patch a case where jr/collect outputs eg +07 as the tz, but most
// specs require +07:00
const trimmed = text.trim();
dataPtr[name] = /[+-]\d\d$/.test(trimmed) ? trimmed + ':00' : trimmed;
} else {
// we have to account for multiple text events for the same field,
// since for whatever reason entities decode into their own text events.
Expand Down
11 changes: 11 additions & 0 deletions test/unit/data/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ describe('submissionToOData', () => {
decimal: { name: 'decimal', type: 'decimal' },
geopoint: { name: 'geopoint', type: 'geopoint' },
geopointNoAlt: { name: 'geopointNoAlt', type: 'geopoint' },
dateTime: { name: 'dateTime', type: 'dateTime' },
dateTimeWhitespace: { name: 'dateTimeWhitespace', type: 'dateTime' },
dateTimeCorrect: { name: 'dateTimeCorrect', type: 'dateTime' },
text: { name: 'text', type: 'text' },
other: { name: 'other', type: 'other' }
};
Expand All @@ -58,6 +61,11 @@ describe('submissionToOData', () => {
<decimal>3.14</decimal>
<geopoint>4.8 15.16 23.42</geopoint>
<geopointNoAlt>11.38 -11.38</geopointNoAlt>
<dateTime>2019-01-01T00:00:00.000-08</dateTime>
<dateTimeWhitespace>
2019-01-01T00:00:00.000-08
</dateTimeWhitespace>
<dateTimeCorrect>2019-01-01T00:00:00.000-08:00</dateTimeCorrect>
<text>hello</text>
<other>what could it be?</other>
</data>`);
Expand All @@ -69,6 +77,9 @@ describe('submissionToOData', () => {
decimal: 3.14,
geopoint: { type: 'Point', coordinates: [ 15.16, 4.8, 23.42 ] },
geopointNoAlt: { type: 'Point', coordinates: [ -11.38, 11.38 ] },
dateTime: '2019-01-01T00:00:00.000-08:00',
dateTimeWhitespace: '2019-01-01T00:00:00.000-08:00',
dateTimeCorrect: '2019-01-01T00:00:00.000-08:00',
text: 'hello',
other: 'what could it be?'
}]);
Expand Down

0 comments on commit 8c18677

Please sign in to comment.