Skip to content

Commit 6eae4ad

Browse files
committed
formatDateWithCityAndTZ
1 parent b7974d5 commit 6eae4ad

File tree

1 file changed

+13
-6
lines changed
  • services/static-webserver/client/source/class/osparc/utils

1 file changed

+13
-6
lines changed

services/static-webserver/client/source/class/osparc/utils/Utils.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,9 @@ qx.Class.define("osparc.utils.Utils", {
637637

638638
/**
639639
* @param {Date} date - The date to format.
640-
* @returns {String} - The formatted date string with city name. Sep 4, 1986, 17:00 Zurich
640+
* @returns {String} - The formatted date string with city name and timezone. Sep 4, 1986, 17:00 Zurich (GMT+02:00)
641641
*/
642-
formatDateWithCity: function(date) {
642+
formatDateWithCityAndTZ: function(date) {
643643
// Short date/time formatter
644644
const options = {
645645
year: "numeric", // 1986
@@ -653,12 +653,19 @@ qx.Class.define("osparc.utils.Utils", {
653653
const dtf = new Intl.DateTimeFormat("en-US", options);
654654
const formatted = dtf.format(date);
655655

656-
// Extract timezone, e.g. "Europe/Zurich"
656+
// Timezone city
657657
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
658-
659-
// Get the city part (last token after /)
660658
const city = tz.split("/").pop().replace("_", " ");
661-
return `${formatted} (${city})`;
659+
660+
// UTC offset (minutes → +HH:MM)
661+
const offsetMinutes = -date.getTimezoneOffset(); // JS returns opposite sign
662+
const sign = offsetMinutes >= 0 ? "+" : "-";
663+
const absMinutes = Math.abs(offsetMinutes);
664+
const hours = String(Math.floor(absMinutes / 60)).padStart(2, "0");
665+
const minutes = String(absMinutes % 60).padStart(2, "0");
666+
const offsetStr = `GMT${sign}${hours}:${minutes}`;
667+
668+
return `${formatted} ${city} (${offsetStr})`;
662669
},
663670

664671
formatMsToHHMMSS: function(ms) {

0 commit comments

Comments
 (0)