fixed datetime filtering #912

This commit is contained in:
SPRINX0\prochazka
2024-10-08 14:38:46 +02:00
parent 4459347169
commit 6806620d90
6 changed files with 19 additions and 7 deletions

View File

@@ -24,6 +24,7 @@
"@types/parsimmon": "^1.10.1",
"dbgate-tools": "^5.0.0-alpha.1",
"lodash": "^4.17.21",
"date-fns": "^4.1.0",
"moment": "^2.24.0",
"parsimmon": "^1.13.0"
}

View File

@@ -1,11 +1,19 @@
import { arrayToHexString, isTypeDateTime } from 'dbgate-tools';
import moment from 'moment';
import { format, toDate } from 'date-fns';
import _isString from 'lodash/isString';
export type FilterMultipleValuesMode = 'is' | 'is_not' | 'contains' | 'begins' | 'ends';
function getDateStringWithoutTimeZone(dateString) {
if (_isString(dateString)) {
return dateString.replace(/Z|([+-]\d{2}:\d{2})$/, '');
}
return dateString;
}
export function getFilterValueExpression(value, dataType?) {
if (value == null) return 'NULL';
if (isTypeDateTime(dataType)) return moment(value).format('YYYY-MM-DD HH:mm:ss');
if (isTypeDateTime(dataType)) return format(toDate(getDateStringWithoutTimeZone(value)), 'yyyy-MM-dd HH:mm:ss');
if (value === true) return 'TRUE';
if (value === false) return 'FALSE';
if (value.$oid) return `ObjectId("${value.$oid}")`;