LuisSanchez commented on code in PR #36486:
URL: https://github.com/apache/superset/pull/36486#discussion_r2625168757


##########
superset-frontend/packages/superset-ui-core/src/components/TimezoneSelector/index.tsx:
##########
@@ -45,117 +63,160 @@ const offsetsToName = {
   '060': ['GMT Standard Time - London', 'British Summer Time'],
 };
 
-export type TimezoneSelectorProps = {
-  onTimezoneChange: (value: string) => void;
-  timezone?: string | null;
-  minWidth?: string;
-};
+let cachedTimezoneOptions: TimezoneOption[] | null = null;
+let computePromise: Promise<TimezoneOption[]> | null = null;
+
+function getOffsetKey(timezoneName: string): string {
+  return (
+    JANUARY_REF.tz(timezoneName).utcOffset().toString() +
+    JULY_REF.tz(timezoneName).utcOffset().toString()
+  );
+}
+
+function getTimezoneDisplayName(
+  timezoneName: string,
+  currentDate: ReturnType<typeof extendedDayjs>,
+): string {
+  const offsetKey = getOffsetKey(timezoneName);
+  const dateInZone = currentDate.tz(timezoneName);
+  const isDSTActive = isDST(dateInZone, timezoneName);
+  const namePair = offsetsToName[offsetKey];
+  return namePair ? (isDSTActive ? namePair[1] : namePair[0]) : timezoneName;
+}
+
+function computeTimezoneOptions(): TimezoneOption[] {
+  const currentDate = extendedDayjs(new Date());
+  const allZones = Intl.supportedValuesOf('timeZone');
+  const seenLabels = new Set<string>();
+  const options: TimezoneOption[] = [];
+
+  for (const zone of allZones) {
+    const offsetKey = getOffsetKey(zone);
+    const displayName = getTimezoneDisplayName(zone, currentDate);
+    const offset = extendedDayjs.tz(currentDate, zone).format('Z');
+    const label = `GMT ${offset} (${displayName})`;
+
+    if (!seenLabels.has(label)) {
+      seenLabels.add(label);
+      options.push({
+        label,
+        value: zone,
+        offsets: offsetKey,
+        timezoneName: zone,
+      });
+    }
+  }
+
+  // Pre-sort timezone options by time offset
+  options.sort(
+    (a, b) =>
+      extendedDayjs.tz(currentDate, a.timezoneName).utcOffset() -
+      extendedDayjs.tz(currentDate, b.timezoneName).utcOffset(),
+  );

Review Comment:
   This does not work as suggested, it will sort the array from -01:00 to -11:00



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to