Browse Source

fix(nc-gui): some more imporvements in showing correct date time

pull/7611/head
DarkPhoenix2704 7 months ago
parent
commit
2d0be6faec
  1. 82
      packages/nocodb/src/db/conditionV2.ts

82
packages/nocodb/src/db/conditionV2.ts

@ -725,7 +725,7 @@ const parseConditionV2 = async (
].includes(column.uidt) ].includes(column.uidt)
) { ) {
if (qb.client.config.client === 'pg') { if (qb.client.config.client === 'pg') {
// todo: enbale back if group by date required custom implementation // todo: enable back if group by date required custom implementation
// if ((filter as any).groupby) // if ((filter as any).groupby)
// qb = qb.where(knex.raw('??::timestamp = ?', [field, val])); // qb = qb.where(knex.raw('??::timestamp = ?', [field, val]));
// else // else
@ -899,11 +899,21 @@ const parseConditionV2 = async (
case 'gt': case 'gt':
{ {
const gt_op = customWhereClause ? '<' : '>'; const gt_op = customWhereClause ? '<' : '>';
qb = qb.where(field, gt_op, val); // If the column is a datetime and the client is pg and the value has a timezone offset at the end
if (column.uidt === UITypes.Rating) { // then we need to convert the value to timestamptz before comparing
// unset rating is considered as NULL if (
if (gt_op === '<' && val > 0) { column.uidt === UITypes.DateTime &&
qb = qb.orWhereNull(field); qb.client.config.client === 'pg' &&
val.match(/[+-]\d{2}:\d{2}$/)
) {
qb.where(field, gt_op, knex.raw('?::timestamptz', [val]));
} else {
qb = qb.where(field, gt_op, val);
if (column.uidt === UITypes.Rating) {
// unset rating is considered as NULL
if (gt_op === '<' && val > 0) {
qb = qb.orWhereNull(field);
}
} }
} }
} }
@ -912,11 +922,21 @@ const parseConditionV2 = async (
case 'gte': case 'gte':
{ {
const ge_op = customWhereClause ? '<=' : '>='; const ge_op = customWhereClause ? '<=' : '>=';
qb = qb.where(field, ge_op, val); // If the column is a datetime and the client is pg and the value has a timezone offset at the end
if (column.uidt === UITypes.Rating) { // then we need to convert the value to timestamptz before comparing
// unset rating is considered as NULL if (
if (ge_op === '<=' || (ge_op === '>=' && val === 0)) { column.uidt === UITypes.DateTime &&
qb = qb.orWhereNull(field); qb.client.config.client === 'pg' &&
val.match(/[+-]\d{2}:\d{2}$/)
) {
qb.where(field, ge_op, knex.raw('?::timestamptz', [val]));
} else {
qb = qb.where(field, ge_op, val);
if (column.uidt === UITypes.Rating) {
// unset rating is considered as NULL
if (ge_op === '<=' || (ge_op === '>=' && val === 0)) {
qb = qb.orWhereNull(field);
}
} }
} }
} }
@ -924,11 +944,21 @@ const parseConditionV2 = async (
case 'lt': case 'lt':
{ {
const lt_op = customWhereClause ? '>' : '<'; const lt_op = customWhereClause ? '>' : '<';
qb = qb.where(field, lt_op, val); // If the column is a datetime and the client is pg and the value has a timezone offset at the end
if (column.uidt === UITypes.Rating) { // then we need to convert the value to timestamptz before comparing
// unset number is considered as NULL if (
if (lt_op === '<' && val > 0) { column.uidt === UITypes.DateTime &&
qb = qb.orWhereNull(field); qb.client.config.client === 'pg' &&
val.match(/[+-]\d{2}:\d{2}$/)
) {
qb.where(field, lt_op, knex.raw('?::timestamptz', [val]));
} else {
qb = qb.where(field, lt_op, val);
if (column.uidt === UITypes.Rating) {
// unset number is considered as NULL
if (lt_op === '<' && val > 0) {
qb = qb.orWhereNull(field);
}
} }
} }
} }
@ -938,11 +968,21 @@ const parseConditionV2 = async (
case 'lte': case 'lte':
{ {
const le_op = customWhereClause ? '>=' : '<='; const le_op = customWhereClause ? '>=' : '<=';
qb = qb.where(field, le_op, val); // If the column is a datetime and the client is pg and the value has a timezone offset at the end
if (column.uidt === UITypes.Rating) { // then we need to convert the value to timestamptz before comparing
// unset number is considered as NULL if (
if (le_op === '<=' || (le_op === '>=' && val === 0)) { column.uidt === UITypes.DateTime &&
qb = qb.orWhereNull(field); qb.client.config.client === 'pg' &&
val.match(/[+-]\d{2}:\d{2}$/)
) {
qb.where(field, le_op, knex.raw('?::timestamptz', [val]));
} else {
qb = qb.where(field, le_op, val);
if (column.uidt === UITypes.Rating) {
// unset number is considered as NULL
if (le_op === '<=' || (le_op === '>=' && val === 0)) {
qb = qb.orWhereNull(field);
}
} }
} }
} }

Loading…
Cancel
Save