Skip to content

Commit dcd1373

Browse files
authored
Merge pull request #1162 from MenamAfzal/add/timezone-name
Added TimeZoneName in JSON return Object in TimeZone
2 parents 4ae6762 + 68be43e commit dcd1373

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,16 @@ export const dateRangeControl = (function () {
462462
.build();
463463
})();
464464

465-
const getTimeZoneInfo = (timeZone: any, othereTimeZone: any) => {
466-
const tz = timeZone === 'UserChoice' ? othereTimeZone : timeZone ;
467-
return {
468-
TimeZone: tz,
469-
Offset: dayjs().tz(tz).format('Z') // Get the UTC offset for the selected timezone
470-
};
471-
};
465+
const getTimeZoneInfo = (timeZone: any, otherTimeZone: any) => {
466+
const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone;
467+
468+
const dateInTz = dayjs().tz(tz);
469+
const offset = dateInTz.format('Z');
470+
const timeZoneName = new Intl.DateTimeFormat('en-US', { timeZone: tz, timeZoneName: 'short' })
471+
.formatToParts().find(part => part.type === 'timeZoneName')?.value;
472+
473+
return { TimeZone: tz, Offset: offset, Name: timeZoneName };
474+
};
472475

473476
export const DatePickerComp = withExposingConfigs(datePickerControl, [
474477
depsConfig({

client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,16 @@ export const timeRangeControl = (function () {
414414
.build();
415415
})();
416416

417-
const getTimeZoneInfo = (timeZone: any, othereTimeZone: any) => {
418-
const tz = timeZone === 'UserChoice' ? othereTimeZone : timeZone ;
419-
return {
420-
TimeZone: tz,
421-
Offset: dayjs().tz(tz).format('Z') // Get the UTC offset for the selected timezone
422-
};
423-
};
417+
const getTimeZoneInfo = (timeZone: any, otherTimeZone: any) => {
418+
const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone;
419+
420+
const dateInTz = dayjs().tz(tz);
421+
const offset = dateInTz.format('Z');
422+
const timeZoneName = new Intl.DateTimeFormat('en-US', { timeZone: tz, timeZoneName: 'short' })
423+
.formatToParts().find(part => part.type === 'timeZoneName')?.value;
424+
425+
return { TimeZone: tz, Offset: offset, Name: timeZoneName };
426+
};
424427

425428
export const TimePickerComp = withExposingConfigs(timePickerControl, [
426429
new NameConfig("value", trans("export.timePickerValueDesc")),

0 commit comments

Comments
 (0)