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

fix: convert YYYY-MM-DD hh:mm:ss.s to epoch time #822

Merged
merged 1 commit into from
Oct 3, 2023
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
5 changes: 5 additions & 0 deletions .changeset/friendly-waves-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@koopjs/featureserver': patch
---

- handle SQL date types in field defs
14 changes: 7 additions & 7 deletions packages/featureserver/coverage-unit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/featureserver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"iso-datestring-validator": "^2.2.2",
"joi": "^17.10.2",
"lodash": "^4.17.21",
"postgres-date": "^2.1.0",
"wkt-parser": "^1.3.3"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/featureserver/src/helpers/data-type-utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const _ = require('lodash');
const {
isValidISODateString,
isValidDate
isValidDate,
} = require('iso-datestring-validator');
const dateTimeParser = require('postgres-date');

const PROBLEMATIC_STRING_SYMBOLS = ['(', '[', '*', '+', '\\', '?'];

Expand All @@ -24,7 +25,7 @@ function isDate (value) {
return false;
}

return (value instanceof Date || (typeof value === 'string') && (isValidDate(value) || isValidISODateString(value)));
return (value instanceof Date || (typeof value === 'string') && !!(dateTimeParser(value) || isValidDate(value) || isValidISODateString(value)));
}

module.exports = {
Expand Down
14 changes: 13 additions & 1 deletion packages/featureserver/src/helpers/data-type-utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ describe('isDate', () => {
});

it('should return true for ISO string', () => {
getDataTypeFromValue(new Date().toISOString()).should.equal('Date');
isDate(new Date().toISOString()).should.equal(true);
});

it('should return true for SQL Date', () => {
isDate('2020-10-01').should.equal(true);
});

it('should return true for SQL Datetime', () => {
isDate('2020-10-01 10:31:45.000').should.equal(true);
});

it('should return false for YYYY/MM/DD', () => {
isDate('2020/10/01').should.equal(false);
});

it('should return false for number', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/winnow/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.