Skip to content

Fix tzlocal issue #1126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
geier committed May 7, 2022
commit 534f5107df4a64b958ed9879ad0f049cf83eb737
11 changes: 8 additions & 3 deletions khal/settings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

import datetime as dt
import glob
import logging
import os
from os.path import expanduser, expandvars, join
from typing import Optional

import pytz
import xdg
Expand All @@ -38,13 +40,16 @@
logger = logging.getLogger('khal')


def is_timezone(tzstring):
"""tries to convert tzstring into a pytz timezone
def is_timezone(tzstring: Optional[str]) -> dt.tzinfo:
"""tries to convert tzstring into a pytz timezone or return local timezone

raises a VdtvalueError if tzstring is not valid
"""
if not tzstring:
return get_localzone()
# later version of tzlocal return zoneinfo (not pytz) timezones
# as a lot of our other code can't deal with this yet, we need to force
# pytz timezones for the time being
return pytz.timezone(str(get_localzone()))
try:
return pytz.timezone(tzstring)
except pytz.UnknownTimeZoneError:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'configobj',
# https://github.com/untitaker/python-atomicwrites/commit/4d12f23227b6a944ab1d99c507a69fdbc7c9ed6d # noqa
'atomicwrites>=0.1.7',
'tzlocal>=1.0,<3',
'tzlocal>=1.0',
]

test_requirements = [
Expand Down
8 changes: 7 additions & 1 deletion tests/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os.path

import pytest
from tzlocal import get_localzone
from tzlocal import get_localzone as _get_localzone
from validate import VdtValueError

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


def get_localzone():
# this reproduces the code in settings.util for the time being
import pytz
return pytz.timezone(str(_get_localzone()))


class TestSettings:
def test_simple_config(self):
config = get_config(
Expand Down