Skip to content

Commit 86600d6

Browse files
committed
[Dashboard] Fix timezone_utils to deal with daylight savings
The `Dashboard Server Timezone` is currently incorrect in when running in a timezone with daylight savings. Fixing that resolution with python `tzlocal`. Signed-off-by: Brendan Miller <6900229+bhmiller@users.noreply.github.com>
1 parent 9b3ad79 commit 86600d6

File tree

2 files changed

+3
-43
lines changed

2 files changed

+3
-43
lines changed

python/ray/dashboard/optional_deps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import aiohttp.web # noqa: F401
88
import aiohttp_cors # noqa: F401
99
import grpc # noqa: F401
10+
import tzlocal # noqa: F401
1011

1112
# These checks have to come first because aiohttp looks
1213
# for opencensus, too, and raises a different error otherwise.
Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,5 @@
1-
import logging
21
from datetime import datetime
3-
4-
logger = logging.getLogger(__name__)
5-
6-
timezones = [
7-
{"offset": "-12:00", "value": "Etc/+12"},
8-
{"offset": "-11:00", "value": "Pacific/Pago_Pago"},
9-
{"offset": "-10:00", "value": "Pacific/Honolulu"},
10-
{"offset": "-09:00", "value": "America/Anchorage"},
11-
{"offset": "-08:00", "value": "America/Los_Angeles"},
12-
{"offset": "-07:00", "value": "America/Phoenix"},
13-
{"offset": "-06:00", "value": "America/Guatemala"},
14-
{"offset": "-05:00", "value": "America/Bogota"},
15-
{"offset": "-04:00", "value": "America/Halifax"},
16-
{"offset": "-03:30", "value": "America/St_Johns"},
17-
{"offset": "-03:00", "value": "America/Sao_Paulo"},
18-
{"offset": "-02:00", "value": "America/Godthab"},
19-
{"offset": "-01:00", "value": "Atlantic/Azores"},
20-
{"offset": "+00:00", "value": "Europe/London"},
21-
{"offset": "+01:00", "value": "Europe/Amsterdam"},
22-
{"offset": "+02:00", "value": "Asia/Amman"},
23-
{"offset": "+03:00", "value": "Asia/Baghdad"},
24-
{"offset": "+03:30", "value": "Asia/Tehran"},
25-
{"offset": "+04:00", "value": "Asia/Dubai"},
26-
{"offset": "+04:30", "value": "Asia/Kabul"},
27-
{"offset": "+05:00", "value": "Asia/Karachi"},
28-
{"offset": "+05:30", "value": "Asia/Kolkata"},
29-
{"offset": "+05:45", "value": "Asia/Kathmandu"},
30-
{"offset": "+06:00", "value": "Asia/Almaty"},
31-
{"offset": "+06:30", "value": "Asia/Yangon"},
32-
{"offset": "+07:00", "value": "Asia/Bangkok"},
33-
{"offset": "+08:00", "value": "Asia/Shanghai"},
34-
{"offset": "+09:00", "value": "Asia/Irkutsk"},
35-
{"offset": "+09:30", "value": "Australia/Adelaide"},
36-
{"offset": "+10:00", "value": "Australia/Brisbane"},
37-
{"offset": "+11:00", "value": "Asia/Magadan"},
38-
{"offset": "+12:00", "value": "Pacific/Auckland"},
39-
{"offset": "+13:00", "value": "Pacific/Tongatapu"},
40-
]
2+
import tzlocal
413

424

435
def get_current_timezone_info():
@@ -48,9 +10,6 @@ def get_current_timezone_info():
4810
sign = "+" if hours >= 0 else "-"
4911
current_offset = f"{sign}{abs(int(hours)):02d}:{abs(int(minutes)):02d}"
5012

51-
current_timezone = next(
52-
(tz for tz in timezones if tz["offset"] == current_offset),
53-
{"offset": None, "value": None},
54-
)
13+
current_timezone = {"offset": current_offset, "value": tzlocal.get_localzone_name()}
5514

5615
return current_timezone

0 commit comments

Comments
 (0)