Skip to content

Commit

Permalink
avoid pytz
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotan committed Jul 3, 2024
1 parent c492f3e commit 5fa67c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
13 changes: 9 additions & 4 deletions nxstools/filewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

import weakref
import time
import pytz
import datetime
import threading
import numpy
# import sys
import sys


#: (:mod:`PNIWriter` or :mod:`H5PYWriter`or :mod:`H5CppWriter`)
Expand Down Expand Up @@ -530,8 +529,14 @@ def currenttime(cls):
tzone = time.tzname[0]
fmt = '%Y-%m-%dT%H:%M:%S.%f%z'
try:
tz = pytz.timezone(tzone)
starttime = tz.localize(datetime.datetime.now())
if sys.version_info >= (3, 9):
import zoneinfo
tz = zoneinfo.ZoneInfo(tzone)
starttime = datetime.datetime.now().replace(tzinfo=tz)
else:
import pytz
tz = pytz.timezone(tzone)
starttime = tz.localize(datetime.datetime.now())
except Exception:
import tzlocal
tz = tzlocal.get_localzone()
Expand Down
12 changes: 9 additions & 3 deletions nxstools/nxsfileinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import stat
import re
import time
import pytz
import datetime
import pwd
import grp
Expand Down Expand Up @@ -3329,8 +3328,15 @@ def isotime(self, tme):
tzone = time.tzname[0]
fmt = '%Y-%m-%dT%H:%M:%S.%f%z'
try:
tz = pytz.timezone(tzone)
starttime = tz.localize(datetime.datetime.fromtimestamp(tme))
if sys.version_info >= (3, 9):
import zoneinfo
tz = zoneinfo.ZoneInfo(tzone)
starttime = \
datetime.datetime.fromtimestamp(tme).replace(tzinfo=tz)
else:
import pytz
tz = pytz.timezone(tzone)
starttime = tz.localize(datetime.datetime.fromtimestamp(tme))
except Exception:
import tzlocal
tz = tzlocal.get_localzone()
Expand Down
11 changes: 8 additions & 3 deletions nxstools/nxsfileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import xml.etree.ElementTree as et
import numpy as np
import math
import pytz
import time
import dateutil.parser
import re
Expand Down Expand Up @@ -109,8 +108,14 @@ def isoDate(text):
if date.tzinfo is None:
tzone = time.tzname[0]
try:
tz = pytz.timezone(tzone)
date = tz.localize(date)
if sys.version_info >= (3, 9):
import zoneinfo
tz = zoneinfo.ZoneInfo(tzone)
date = date.replace(tzinfo=tz)
else:
import pytz
tz = pytz.timezone(tzone)
date = tz.localize(date)
except Exception:
import tzlocal
tz = tzlocal.get_localzone()
Expand Down

0 comments on commit 5fa67c9

Please sign in to comment.