mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 22:36:01 +00:00
fixed datetime filtering #912
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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}")`;
|
||||
|
||||
Reference in New Issue
Block a user