From 13d0584f6175f80842e38ba07f132499185c6fb1 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 8 Jun 2020 16:33:42 +0100
Subject: [PATCH] Issue #3016427 by sysosmaster, nod_, kkalashnikov, Neslee
 Canil Pinto, alexpott, quicksketch: Default timezone selection incorrect

---
 core/misc/timezone.es6.js | 8 ++++++++
 core/misc/timezone.js     | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/core/misc/timezone.es6.js b/core/misc/timezone.es6.js
index 64c88c78d1b2..530c5c8c08c9 100644
--- a/core/misc/timezone.es6.js
+++ b/core/misc/timezone.es6.js
@@ -15,6 +15,14 @@
         .find('.timezone-detect')
         .once('timezone');
       if ($timezone.length) {
+        const tz = new Intl.DateTimeFormat().resolvedOptions().timeZone;
+        // Ensure that the timezone value returned by the browser is supported
+        // by the server.
+        if (tz && $timezone.find(`option[value="${tz}"]`).length) {
+          $timezone.val(tz);
+          return;
+        }
+
         const dateString = Date();
         // In some client environments, date strings include a time zone
         // abbreviation, between 3 and 5 letters enclosed in parentheses,
diff --git a/core/misc/timezone.js b/core/misc/timezone.js
index 3df14ad641ad..94bb564acd87 100644
--- a/core/misc/timezone.js
+++ b/core/misc/timezone.js
@@ -11,6 +11,13 @@
       var $timezone = $(context).find('.timezone-detect').once('timezone');
 
       if ($timezone.length) {
+        var tz = new Intl.DateTimeFormat().resolvedOptions().timeZone;
+
+        if (tz && $timezone.find("option[value=\"".concat(tz, "\"]")).length) {
+          $timezone.val(tz);
+          return;
+        }
+
         var dateString = Date();
         var matches = dateString.match(/\(([A-Z]{3,5})\)/);
         var abbreviation = matches ? matches[1] : 0;
-- 
GitLab