Skip to content

Commit eca6772

Browse files
committed
fix missing UTC
1 parent 2ee3083 commit eca6772

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pydl/pydlutils/yanny.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
from . import PydlutilsException, PydlutilsUserWarning
5858

5959

60+
try:
61+
UTC = datetime.UTC
62+
except AttributeError:
63+
from zoneinfo import ZoneInfo
64+
UTC = ZoneInfo('UTC')
65+
66+
6067
class yanny(OrderedDict):
6168
"""An object interface to a yanny file.
6269
@@ -865,7 +872,7 @@ def write(self, newfile=None, comments=None):
865872
"{0} exists, aborting write!".format(newfile))
866873
if comments is None:
867874
basefile = os.path.basename(newfile)
868-
timestamp = datetime.datetime.now(datetime.UTC).strftime('%Y-%m-%d %H:%M:%S UTC')
875+
timestamp = datetime.datetime.now(UTC).strftime('%Y-%m-%d %H:%M:%S UTC')
869876
comments = f"""#
870877
# {basefile}
871878
#
@@ -947,7 +954,7 @@ def append(self, datatable):
947954
if not isinstance(datatable, dict):
948955
raise ValueError("Data to append is not of the correct type. " +
949956
"Use a dict!")
950-
timestamp = datetime.datetime.now(datetime.UTC).strftime('%Y-%m-%d %H:%M:%S UTC')
957+
timestamp = datetime.datetime.now(UTC).strftime('%Y-%m-%d %H:%M:%S UTC')
951958
contents = ''
952959
#
953960
# Print any key/value pairs

0 commit comments

Comments
 (0)