Skip to content

Commit

Permalink
replace deprecated tz.localize() with datetime.replace() (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotan authored May 23, 2024
1 parent babb7e2 commit 5fa4303
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-05-23 Jan Kotanski <[email protected]>
* replace deprecated tz.localize() with datetime.replace() (#640)
* tagged as v4.1.1

2024-05-22 Jan Kotanski <[email protected]>
* adapt the entry name in the appendentry mode to NXS_FileRecorder v3.21.0 (#637)
* tagged as v4.1.0
Expand Down
6 changes: 5 additions & 1 deletion nxstools/filewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import datetime
import threading
import numpy
import sys


#: (:mod:`PNIWriter` or :mod:`H5PYWriter`or :mod:`H5CppWriter`)
Expand Down Expand Up @@ -533,7 +534,10 @@ def currenttime(cls):
import tzlocal
tz = tzlocal.get_localzone()
fmt = '%Y-%m-%dT%H:%M:%S.%f%z'
starttime = tz.localize(datetime.datetime.now())
if sys.version_info > (3, 6):
starttime = datetime.datetime.now().replace(tzinfo=tz)
else:
starttime = tz.localize(datetime.datetime.now())
return str(starttime.strftime(fmt))

def default_field(self):
Expand Down
6 changes: 5 additions & 1 deletion nxstools/nxsfileinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,11 @@ def isotime(self, tme):
import tzlocal
tz = tzlocal.get_localzone()
fmt = '%Y-%m-%dT%H:%M:%S.%f%z'
starttime = tz.localize(datetime.datetime.fromtimestamp(tme))
if sys.version_info > (3, 6):
starttime = \
datetime.datetime.fromtimestamp(tme).replace(tzinfo=tz)
else:
starttime = tz.localize(datetime.datetime.fromtimestamp(tme))
return str(starttime.strftime(fmt))

def filterout(self, fpath, filters):
Expand Down
5 changes: 4 additions & 1 deletion nxstools/nxsfileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def isoDate(text):
except Exception:
import tzlocal
tz = tzlocal.get_localzone()
date = tz.localize(date)
if sys.version_info > (3, 6):
date = date.replace(tzinfo=tz)
else:
date = tz.localize(date)
fmt = '%Y-%m-%dT%H:%M:%S.%f%z'
result = str(date.strftime(fmt))
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion nxstools/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
""" NXS tools release version"""

#: (:obj:`str`) package version
__version__ = "4.1.0"
__version__ = "4.1.1"

0 comments on commit 5fa4303

Please sign in to comment.