Skip to content

Commit

Permalink
add localTime
Browse files Browse the repository at this point in the history
增加lTime以适配客户端时间
  • Loading branch information
nightzjp committed Jan 24, 2024
1 parent 3181166 commit 9f41b15
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docSite/content/docs/workflow/modules/variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ weight: 361

除了用户自定义设置的变量外,还会有一些系统变量:

+ **cTime**: 当前时间。例如:2023/3/3 20:22
+ **cTime**: 当前系统时间。例如:2023/3/3 20:
+ **lTime**: 当前本地时间。例如:2023/3/3 20:
4 changes: 4 additions & 0 deletions packages/global/common/time/timezone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ export const getSystemTime = (timeZone: string) => {
const targetTime = now + timezoneDiff * 60 * 60 * 1000;
return dayjs(targetTime).format('YYYY-MM-DD HH:mm:ss');
};

export const getLocalTime = () => {
return dayjs().format('YYYY-MM-DD HH:mm:ss');
};
5 changes: 3 additions & 2 deletions projects/app/src/service/moduleDispatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ModuleItemType } from '@fastgpt/global/core/module/type';
import { replaceVariable } from '@fastgpt/global/common/string/tools';
import { responseWrite } from '@fastgpt/service/common/response';
import { sseResponseEventEnum } from '@fastgpt/service/common/response/constant';
import { getSystemTime } from '@fastgpt/global/common/time/timezone';
import { getLocalTime, getSystemTime } from '@fastgpt/global/common/time/timezone';
import { initRunningModuleType } from '../core/modules/constant';

import { dispatchHistory } from './init/history';
Expand Down Expand Up @@ -342,6 +342,7 @@ export function responseStatus({
/* get system variable */
export function getSystemVariable({ timezone }: { timezone: string }) {
return {
cTime: getSystemTime(timezone)
cTime: getSystemTime(timezone), // 当前时间
lTime: getLocalTime() // 客户端时间
};
}

0 comments on commit 9f41b15

Please sign in to comment.