Skip to content

Commit

Permalink
Update tzlocal to v4.x and remove pytz dependency (#1528)
Browse files Browse the repository at this point in the history
* Update tzlocal to v4.x and remove pytz dependency
* Avoid `unwrap_shim` method
* Remove upper bound of tzlocal version
  • Loading branch information
outa authored Jul 30, 2022
1 parent 049d2a7 commit 62f65ce
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 228 deletions.
17 changes: 7 additions & 10 deletions jrnl/DayOneJournal.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import socket
import time
import uuid
import zoneinfo
from pathlib import Path
from xml.parsers.expat import ExpatError

import pytz
import tzlocal

from jrnl import Entry
Expand All @@ -39,10 +39,6 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)

def open(self):
filenames = [
os.path.join(self.config["journal"], "entries", f)
for f in os.listdir(os.path.join(self.config["journal"], "entries"))
]
filenames = []
for root, dirnames, f in os.walk(self.config["journal"]):
for filename in fnmatch.filter(f, "*.doentry"):
Expand All @@ -56,14 +52,15 @@ def open(self):
pass
else:
try:
timezone = pytz.timezone(dict_entry["Time Zone"])
except (KeyError, pytz.exceptions.UnknownTimeZoneError):
timezone = tzlocal.get_localzone()
timezone = zoneinfo.ZoneInfo(dict_entry["Time Zone"])
except KeyError:
timezone_name = str(tzlocal.get_localzone())
timezone = zoneinfo.ZoneInfo(timezone_name)
date = dict_entry["Creation Date"]
# convert the date to UTC rather than keep messing with
# timezones
if timezone.zone != "UTC":
date = date + timezone.utcoffset(date, is_dst=False)
if timezone.key != "UTC":
date = date.replace(fold=1) + timezone.utcoffset(date)

entry = Entry.Entry(
self,
Expand Down
Loading

0 comments on commit 62f65ce

Please sign in to comment.