Skip to content

Commit 6b0a949

Browse files
committed
Fix tzlocal issue
Newer versions of tzlocal return tzinfo timezones, not pytz ones. Khal can't deal with tzinfo timezones for the moment, so we force pytz timezones when we use tzlocal. This should be removed when we completely migrate to tzinfo. Fix #1092
1 parent 7250d95 commit 6b0a949

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

khal/settings/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121
#
2222

23+
import datetime as dt
2324
import glob
2425
import logging
2526
import os
@@ -38,13 +39,16 @@
3839
logger = logging.getLogger('khal')
3940

4041

41-
def is_timezone(tzstring):
42-
"""tries to convert tzstring into a pytz timezone
42+
def is_timezone(tzstring: str) -> dt.tzinfo:
43+
"""tries to convert tzstring into a pytz timezone or return local timezone
4344
4445
raises a VdtvalueError if tzstring is not valid
4546
"""
4647
if not tzstring:
47-
return get_localzone()
48+
# later version of tzlocal return zoneinfo (not pytz) timezones
49+
# as a lot of our other code can't deal with this yet, we need to force
50+
# pytz timezones for the time being
51+
return pytz.timezone(str(get_localzone()))
4852
try:
4953
return pytz.timezone(tzstring)
5054
except pytz.UnknownTimeZoneError:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'configobj',
2222
# https://github.com/untitaker/python-atomicwrites/commit/4d12f23227b6a944ab1d99c507a69fdbc7c9ed6d # noqa
2323
'atomicwrites>=0.1.7',
24-
'tzlocal>=1.0,<3',
24+
'tzlocal>=1.0',
2525
]
2626

2727
test_requirements = [

tests/settings_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os.path
33

44
import pytest
5-
from tzlocal import get_localzone
5+
from tzlocal import get_localzone as _get_localzone
66
from validate import VdtValueError
77

88
from khal.settings import get_config
@@ -17,6 +17,12 @@
1717
PATH = __file__.rsplit('/', 1)[0] + '/configs/'
1818

1919

20+
def get_localzone():
21+
# this reproduces the code in settings.util for the time being
22+
import pytz
23+
return pytz.timezone(str(_get_localzone()))
24+
25+
2026
class TestSettings:
2127
def test_simple_config(self):
2228
config = get_config(

0 commit comments

Comments
 (0)