File tree Expand file tree Collapse file tree 2 files changed +18
-9
lines changed
Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 1313from ._version import __version__
1414from .constants import AIR_MAIN_CONSTITUENTS_MOLAR_FRACTION , MM , K
1515from .profiles .schema import schema
16- from .profiles .util import molar_mass
16+ from .profiles .util import molar_mass , utcnow
1717from .units import to_quantity , ureg
1818
1919logger = 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 "
Original file line number Diff line number Diff line change 11"""Utility module."""
22
33import datetime
4+ import sys
45import typing as t
56
67import numpy as np
1011from ..constants import MM , K
1112from ..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
2332def number_density (p : pint .Quantity , t : pint .Quantity ) -> pint .Quantity :
You can’t perform that action at this time.
0 commit comments