Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/joseki/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ._version import __version__
from .constants import AIR_MAIN_CONSTITUENTS_MOLAR_FRACTION, MM, K
from .profiles.schema import schema
from .profiles.util import molar_mass
from .profiles.util import molar_mass, utcnow
from .units import to_quantity, ureg

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -425,7 +425,7 @@ def rescale(
raise ValueError("Cannot rescale") from e

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

# update history attribute
now = datetime.datetime.utcnow().replace(microsecond=0).isoformat()
now = utcnow()

ds.attrs["history"] += (
f"\n{now} - dropped mole fraction data for molecules "
Expand Down
21 changes: 15 additions & 6 deletions src/joseki/profiles/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utility module."""

import datetime
import sys
import typing as t

import numpy as np
Expand All @@ -10,14 +11,22 @@
from ..constants import MM, K
from ..units import ureg

if sys.version_info[1] < 11:

def utcnow() -> str:
"""Get current UTC time.
def _utcnow():
return datetime.datetime.utcnow()
else:

Returns:
ISO 8601 formatted UTC timestamp.
"""
return datetime.datetime.utcnow().replace(microsecond=0).isoformat()
def _utcnow():
return datetime.datetime.now(datetime.UTC)


def utcnow(isoformat: bool = True):
result = _utcnow()
if isoformat:
return result.replace(microsecond=0).isoformat()
else:
return result


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