chore: filter to date event
Some checks failed
Build docker image / build-and-push (push) Waiting to run
Build pro image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase frontEnd test / frontend-test (18) (push) Waiting to run
NocoBase backend test / sqlite-test (20, false) (push) Has been cancelled
NocoBase backend test / sqlite-test (20, true) (push) Has been cancelled
NocoBase backend test / postgres-test (public, 20, nocobase, false) (push) Has been cancelled
NocoBase backend test / postgres-test (public, 20, nocobase, true) (push) Has been cancelled
NocoBase backend test / postgres-test (public, 20, public, false) (push) Has been cancelled
NocoBase backend test / postgres-test (public, 20, public, true) (push) Has been cancelled
NocoBase backend test / postgres-test (user_schema, 20, nocobase, false) (push) Has been cancelled
NocoBase backend test / postgres-test (user_schema, 20, nocobase, true) (push) Has been cancelled
NocoBase backend test / postgres-test (user_schema, 20, public, false) (push) Has been cancelled
NocoBase backend test / postgres-test (user_schema, 20, public, true) (push) Has been cancelled
NocoBase backend test / mysql-test (20, false) (push) Has been cancelled
NocoBase backend test / mysql-test (20, true) (push) Has been cancelled
NocoBase backend test / mariadb-test (20, false) (push) Has been cancelled
NocoBase backend test / mariadb-test (20, true) (push) Has been cancelled
Test on Windows / build (push) Has been cancelled

This commit is contained in:
Chareice 2024-10-16 23:24:10 +08:00
parent 379ae83862
commit a78f2e1702
No known key found for this signature in database

View File

@ -8,7 +8,7 @@
*/
import { parseDate } from '@nocobase/utils';
import { Op } from 'sequelize';
import { Op, Sequelize } from 'sequelize';
import moment from 'moment';
function isDate(input) {
@ -17,7 +17,7 @@ function isDate(input) {
const toDate = (date, options: any = {}) => {
const { ctx } = options;
const val = isDate(date) ? date : new Date(date);
let val = isDate(date) ? date : new Date(date);
const field = ctx.db.getFieldByPath(ctx.fieldPath);
if (!field) {
@ -25,18 +25,25 @@ const toDate = (date, options: any = {}) => {
}
if (field.constructor.name === 'UnixTimestampField') {
return field.dateToValue(val);
val = field.dateToValue(val);
}
if (field.constructor.name === 'DatetimeNoTzField') {
return moment(val).utcOffset('+00:00').format('YYYY-MM-DD HH:mm:ss');
val = moment(val).utcOffset('+00:00').format('YYYY-MM-DD HH:mm:ss');
}
if (field.constructor.name === 'DateOnlyField') {
return moment(val).format('YYYY-MM-DD HH:mm:ss');
val = moment(val).format('YYYY-MM-DD HH:mm:ss');
}
return val;
const eventObj = {
val,
fieldType: field.type,
};
ctx.db.emit('filterToDate', eventObj);
return eventObj.val;
};
function parseDateTimezone(ctx) {
@ -57,10 +64,6 @@ function parseDateTimezone(ctx) {
return ctx.db.options.timezone;
}
function isDatetimeString(str) {
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(str);
}
export default {
$dateOn(value, ctx) {
const r = parseDate(value, {