Skip to content

Commit 02a0026

Browse files
committed
Fix browser timezone information being lost
1 parent ff04a2e commit 02a0026

File tree

2 files changed

+3
-41
lines changed

2 files changed

+3
-41
lines changed

library/Icinga/Util/TimezoneDetect.php

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ class TimezoneDetect
1515
*/
1616
private static $success;
1717

18-
/**
19-
* Timezone offset in minutes
20-
*
21-
* @var int
22-
*/
23-
private static $offset = 0;
24-
2518
/**
2619
* @var string
2720
*/
@@ -34,13 +27,6 @@ class TimezoneDetect
3427
*/
3528
public static $cookieName = 'icingaweb2-tzo';
3629

37-
/**
38-
* Timezone name
39-
*
40-
* @var string
41-
*/
42-
private static $timezone;
43-
4430
/**
4531
* Create new object and try to identify the timezone
4632
*/
@@ -51,30 +37,11 @@ public function __construct()
5137
}
5238

5339
if (array_key_exists(self::$cookieName, $_COOKIE)) {
54-
$matches = array();
55-
if (preg_match('/\A(-?\d+)[\-,](\d+)\z/', $_COOKIE[self::$cookieName], $matches)) {
56-
$offset = $matches[1];
57-
$timezoneName = timezone_name_from_abbr('', (int) $offset, (int) $matches[2]);
58-
59-
self::$success = (bool) $timezoneName;
60-
if (self::$success) {
61-
self::$offset = $offset;
62-
self::$timezoneName = $timezoneName;
63-
}
64-
}
40+
self::$timezoneName = $_COOKIE[self::$cookieName];
41+
self::$success = true;
6542
}
6643
}
6744

68-
/**
69-
* Get offset
70-
*
71-
* @return int
72-
*/
73-
public function getOffset()
74-
{
75-
return self::$offset;
76-
}
77-
7845
/**
7946
* Get timezone name
8047
*
@@ -102,6 +69,5 @@ public function reset()
10269
{
10370
self::$success = null;
10471
self::$timezoneName = null;
105-
self::$offset = 0;
10672
}
10773
}

public/js/icinga/timezone.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,11 @@
5151
* Write timezone information into cookie
5252
*/
5353
writeTimezone: function() {
54-
var date = new Date();
55-
var timezoneOffset = (date.getTimezoneOffset()*60) * -1;
56-
var dst = date.isDst();
57-
5854
if (this.readCookie(this.cookieName)) {
5955
return;
6056
}
6157

62-
this.writeCookie(this.cookieName, timezoneOffset + '-' + Number(dst), 1);
58+
this.writeCookie(this.cookieName, Intl.DateTimeFormat().resolvedOptions().timeZone);
6359
},
6460

6561
/**

0 commit comments

Comments
 (0)