Merge branch 'next' into develop

This commit is contained in:
nocobase[bot] 2024-12-08 05:15:33 +00:00
commit aa709c3e70

View File

@ -8,6 +8,7 @@
*/ */
import { Col, Formatter } from './formatter'; import { Col, Formatter } from './formatter';
import moment from 'moment-timezone';
export class MySQLFormatter extends Formatter { export class MySQLFormatter extends Formatter {
convertFormat(format: string) { convertFormat(format: string) {
@ -21,14 +22,10 @@ export class MySQLFormatter extends Formatter {
} }
formatDate(field: Col, format: string, timezoneOffset?: string) { formatDate(field: Col, format: string, timezoneOffset?: string) {
const timezone = this.getTimezoneByOffset(timezoneOffset); const tz = moment.tz(process.env.TZ || 'UTC').format('Z');
format = this.convertFormat(format); format = this.convertFormat(format);
if (timezone) { if (timezoneOffset && tz !== timezoneOffset) {
return this.sequelize.fn( return this.sequelize.fn('date_format', this.sequelize.fn('convert_tz', field, tz, timezoneOffset), format);
'date_format',
this.sequelize.fn('convert_tz', field, process.env.TZ || 'UTC', timezone),
format,
);
} }
return this.sequelize.fn('date_format', field, format); return this.sequelize.fn('date_format', field, format);
} }