fix: createAt field error
This commit is contained in:
parent
a5bf64eb93
commit
bc167dca1c
@ -0,0 +1,16 @@
|
||||
CREATE
|
||||
OR REPLACE FUNCTION format_timestamp_with_timezone (
|
||||
date_val TIMESTAMP WITH TIME ZONE,
|
||||
timezone_val TEXT,
|
||||
format_val TEXT
|
||||
) RETURNS TEXT AS $$
|
||||
DECLARE
|
||||
formatted_text text;
|
||||
BEGIN
|
||||
-- 使用 to_char 函数进行格式化
|
||||
SELECT to_char(date_val AT TIME ZONE timezone_val, format_val) INTO formatted_text;
|
||||
|
||||
-- 返回格式化后的字符串
|
||||
RETURN formatted_text;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
@ -23,7 +23,8 @@
|
||||
"lodash": "^4.17.21",
|
||||
"react": "^18.2.0",
|
||||
"react-error-boundary": "^4.0.10",
|
||||
"react-i18next": "^11.15.1"
|
||||
"react-i18next": "^11.15.1",
|
||||
"sequelize": "^6.26.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nocobase/actions": "workspace:*",
|
||||
|
@ -1,4 +1,13 @@
|
||||
export const dateFormatFn = (sequelize: any, dialect: string, field: string, format: string, timezone: string) => {
|
||||
import { Sequelize } from 'sequelize';
|
||||
|
||||
export const dateFormatFn = (
|
||||
sequelize: Sequelize,
|
||||
dialect: string,
|
||||
field: string,
|
||||
format: string,
|
||||
timezone: string,
|
||||
) => {
|
||||
const reversedTimezone = timezone[0] === '+' ? '-' + timezone.slice(1) : '+' + timezone.slice(1);
|
||||
switch (dialect) {
|
||||
case 'sqlite':
|
||||
format = format
|
||||
@ -21,18 +30,13 @@ export const dateFormatFn = (sequelize: any, dialect: string, field: string, for
|
||||
return sequelize.fn('date_format', sequelize.col(field), format);
|
||||
case 'postgres':
|
||||
format = format.replace(/hh/g, 'HH24').replace(/mm/g, 'MI').replace(/ss/g, 'SS');
|
||||
// return sequelize.fn('to_char', sequelize.col(field), format);
|
||||
return sequelize.fn(
|
||||
'to_char',
|
||||
sequelize.literal(`(${field} AT TIME ZONE 'UTC') AT TIME ZONE '${timezone}'`),
|
||||
format,
|
||||
);
|
||||
return sequelize.fn('format_timestamp_with_timezone', sequelize.col(field), reversedTimezone, format);
|
||||
default:
|
||||
return sequelize.col(field);
|
||||
}
|
||||
};
|
||||
|
||||
export const formatFn = (sequelize: any, dialect: string, field: string, format: string) => {
|
||||
export const formatFn = (sequelize: Sequelize, dialect: string, field: string, format: string) => {
|
||||
switch (dialect) {
|
||||
case 'sqlite':
|
||||
case 'postgres':
|
||||
@ -42,7 +46,7 @@ export const formatFn = (sequelize: any, dialect: string, field: string, format:
|
||||
}
|
||||
};
|
||||
|
||||
export const formatter = (sequelize: any, type: string, field: string, format: string, timezone: string) => {
|
||||
export const formatter = (sequelize: Sequelize, type: string, field: string, format: string, timezone: string) => {
|
||||
const dialect = sequelize.getDialect();
|
||||
switch (type) {
|
||||
case 'date':
|
||||
|
@ -2441,6 +2441,9 @@ importers:
|
||||
react-i18next:
|
||||
specifier: ^11.15.1
|
||||
version: 11.18.6(i18next@22.5.1)(react-dom@18.2.0)(react@18.2.0)
|
||||
sequelize:
|
||||
specifier: ^6.26.0
|
||||
version: 6.35.2
|
||||
|
||||
packages/plugins/@nocobase/plugin-disable-pm-add:
|
||||
dependencies:
|
||||
|
Loading…
Reference in New Issue
Block a user