Skip to content

Commit

Permalink
Merge pull request #14 from niccokunzmann/issue-13
Browse files Browse the repository at this point in the history
Switch to zoneinfo
  • Loading branch information
niccokunzmann authored Sep 30, 2024
2 parents eeff124 + 0e49b58 commit e4af345
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
matrix:
config:
# [Python version, tox env]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11", "py311"]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ __pycache__
ENV2
*.swp
.tox
.venv
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ how to go about it.
Changelog
---------

- v1.0.0

- Use `zoneinfo` instead of `pytz`
- Test compatibility with `pytz` and `zoneinfo` as argument to `to_standard`
- Remove `pytz` as a dependency
- Add `tzdata` as a dependency
- Add typing
- Update Python versions

- v0.0.7

- Rename master branch to main
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
icalendar
pytz
tzdata
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
HERE = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, HERE) # for package import

__version__ = "0.0.7"
__version__ = "1.0.1"
__author__ = 'Nicco Kunzmann'


Expand Down Expand Up @@ -128,13 +128,10 @@ def run(self):
'Intended Audience :: Developers',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
development_state
],
zip_safe=True,
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pytest
restructuredtext-lint
pygments
icalendar>=5.0.11
pytz
7 changes: 5 additions & 2 deletions test/test_convert_examples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This test converts example calendars"""
import pytest
import x_wr_timezone
import zoneinfo
import pytz


Expand Down Expand Up @@ -93,8 +94,10 @@ def test_conversion_adds_the_time_zone(to_standard, calendars, calendar_name, co

@pytest.mark.parametrize("tz,line,message,calendar_name", [
("Europe/Paris", ("DTSTART", "TZID=Europe/Paris" ,"20211223T030000"), "(1) Use string as timezone", "single-events-DTSTART-DTEND.in.ics"),
(pytz.timezone("Europe/Berlin"), ("DTSTART", "TZID=Europe/Berlin", "20211223T030000"), "(2) Use pytz.timezone as timezone", "single-events-DTSTART-DTEND.in.ics"),
(pytz.UTC, ("DTSTART", "20211222T170000Z"), "(3) Use pytz.UTC as timezone", "single-events-DTSTART-DTEND.in.ics"),
(zoneinfo.ZoneInfo("Europe/Berlin"), ("DTSTART", "TZID=Europe/Berlin", "20211223T030000"), "(2) Use zoneinfo's timezone as timezone", "single-events-DTSTART-DTEND.in.ics"),
(zoneinfo.ZoneInfo("UTC"), ("DTSTART", "20211222T170000Z"), "(3) Use zoninfo's UTC as timezone", "single-events-DTSTART-DTEND.in.ics"),
(pytz.timezone("Europe/Berlin"), ("DTSTART", "TZID=Europe/Berlin", "20211223T030000"), "(4) Use pytz.timezone as timezone", "single-events-DTSTART-DTEND.in.ics"),
(pytz.UTC, ("DTSTART", "20211222T170000Z"), "(5) Use pytz.UTC as timezone", "single-events-DTSTART-DTEND.in.ics"),
])
def test_timezone_parameter(calendars, tz, line, message, calendar_name):
calendar = calendars[calendar_name]
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py38, py39, py310, py311
envlist = py39, py310, py311, py312
requires = setuptools>=68.2.2

[testenv]
Expand Down
11 changes: 7 additions & 4 deletions x_wr_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Bring calendars using X-WR-TIMEZONE into RFC 5545 form."""
import sys
import pytz
import zoneinfo
from icalendar.prop import vDDDTypes, vDDDLists
import datetime
import icalendar
from typing import Optional

X_WR_TIMEZONE = "X-WR-TIMEZONE"

Expand Down Expand Up @@ -140,11 +141,13 @@ def walk_value_datetime(self, dt):
if self.is_UTC(dt):
return dt.astimezone(self.new_timezone)
elif self.is_Floating(dt):
return self.new_timezone.localize(dt)
if is_pytz(self.new_timezone):
return self.new_timezone.localize(dt)
return dt.replace(tzinfo=self.new_timezone)
return dt


def to_standard(calendar, timezone=None):
def to_standard(calendar : icalendar.Calendar, timezone:Optional[datetime.tzinfo]=None) -> icalendar.Calendar:
"""Make a calendar that might use X-WR-TIMEZONE compatible with RFC 5545.
Arguments:
Expand All @@ -159,7 +162,7 @@ def to_standard(calendar, timezone=None):
if timezone is None:
timezone = calendar.get(X_WR_TIMEZONE, None)
if timezone is not None and not isinstance(timezone, datetime.tzinfo):
timezone = pytz.timezone(timezone)
timezone = zoneinfo.ZoneInfo(timezone)
if timezone is not None:
walker = UTCChangingWalker(timezone)
return walker.walk(calendar)
Expand Down

0 comments on commit e4af345

Please sign in to comment.