Skip to content

Commit 54ac6f1

Browse files
committed
Fix utcnow warnings
1 parent 7934c02 commit 54ac6f1

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/joseki/accessor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ._version import __version__
1414
from .constants import AIR_MAIN_CONSTITUENTS_MOLAR_FRACTION, MM, K
1515
from .profiles.schema import schema
16-
from .profiles.util import molar_mass
16+
from .profiles.util import molar_mass, utcnow
1717
from .units import to_quantity, ureg
1818

1919
logger = logging.getLogger(__name__)
@@ -425,7 +425,7 @@ def rescale(
425425
raise ValueError("Cannot rescale") from e
426426

427427
# update history attribute
428-
now = datetime.datetime.utcnow().replace(microsecond=0).isoformat()
428+
now = utcnow()
429429
for m in factors.keys():
430430
ds.attrs["history"] += (
431431
f"\n{now} - rescaled {m}'s mole fraction using a scaling "
@@ -473,7 +473,7 @@ def drop_molecules(self, molecules: t.List[str]) -> xr.Dataset:
473473
ds = self._obj
474474

475475
# update history attribute
476-
now = datetime.datetime.utcnow().replace(microsecond=0).isoformat()
476+
now = utcnow()
477477

478478
ds.attrs["history"] += (
479479
f"\n{now} - dropped mole fraction data for molecules "

src/joseki/profiles/util.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Utility module."""
22

33
import datetime
4+
import sys
45
import typing as t
56

67
import numpy as np
@@ -10,14 +11,22 @@
1011
from ..constants import MM, K
1112
from ..units import ureg
1213

14+
if sys.version_info[1] < 11:
1315

14-
def utcnow() -> str:
15-
"""Get current UTC time.
16+
def _utcnow():
17+
return datetime.datetime.utcnow()
18+
else:
1619

17-
Returns:
18-
ISO 8601 formatted UTC timestamp.
19-
"""
20-
return datetime.datetime.utcnow().replace(microsecond=0).isoformat()
20+
def _utcnow():
21+
return datetime.datetime.now(datetime.UTC)
22+
23+
24+
def utcnow(isoformat: bool = True):
25+
result = _utcnow()
26+
if isoformat:
27+
return result.replace(microsecond=0).isoformat()
28+
else:
29+
return result
2130

2231

2332
def number_density(p: pint.Quantity, t: pint.Quantity) -> pint.Quantity:

0 commit comments

Comments
 (0)