From e46c61136661031dd12f8d7ada227791a039089a Mon Sep 17 00:00:00 2001 From: MenamAfzal Date: Fri, 13 Sep 2024 16:43:01 +0500 Subject: [PATCH] added timeZone name in JSON obj --- .../src/comps/comps/dateComp/dateComp.tsx | 17 ++++++++++------- .../src/comps/comps/dateComp/timeComp.tsx | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx b/client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx index c180ad917..89ff6a611 100644 --- a/client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx @@ -462,13 +462,16 @@ export const dateRangeControl = (function () { .build(); })(); -const getTimeZoneInfo = (timeZone: any, othereTimeZone: any) => { - const tz = timeZone === 'UserChoice' ? othereTimeZone : timeZone ; - return { - TimeZone: tz, - Offset: dayjs().tz(tz).format('Z') // Get the UTC offset for the selected timezone - }; -}; +const getTimeZoneInfo = (timeZone: any, otherTimeZone: any) => { + const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone; + + const dateInTz = dayjs().tz(tz); + const offset = dateInTz.format('Z'); + const timeZoneName = new Intl.DateTimeFormat('en-US', { timeZone: tz, timeZoneName: 'short' }) + .formatToParts().find(part => part.type === 'timeZoneName')?.value; + + return { TimeZone: tz, Offset: offset, Name: timeZoneName }; +}; export const DatePickerComp = withExposingConfigs(datePickerControl, [ depsConfig({ diff --git a/client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx b/client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx index 9e74e3d3f..e34ae15a8 100644 --- a/client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx @@ -414,13 +414,16 @@ export const timeRangeControl = (function () { .build(); })(); -const getTimeZoneInfo = (timeZone: any, othereTimeZone: any) => { - const tz = timeZone === 'UserChoice' ? othereTimeZone : timeZone ; - return { - TimeZone: tz, - Offset: dayjs().tz(tz).format('Z') // Get the UTC offset for the selected timezone - }; -}; +const getTimeZoneInfo = (timeZone: any, otherTimeZone: any) => { + const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone; + + const dateInTz = dayjs().tz(tz); + const offset = dateInTz.format('Z'); + const timeZoneName = new Intl.DateTimeFormat('en-US', { timeZone: tz, timeZoneName: 'short' }) + .formatToParts().find(part => part.type === 'timeZoneName')?.value; + + return { TimeZone: tz, Offset: offset, Name: timeZoneName }; +}; export const TimePickerComp = withExposingConfigs(timePickerControl, [ new NameConfig("value", trans("export.timePickerValueDesc")),