From 2e8fed5399ccb730ef27b96dacb6662d120857a0 Mon Sep 17 00:00:00 2001 From: atuonufure Date: Fri, 18 Aug 2023 11:52:46 +0200 Subject: [PATCH] Update FP_Time and FP_DateTime --- fhirpathpy/engine/invocations/datetime.py | 8 ++++---- fhirpathpy/engine/nodes.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/fhirpathpy/engine/invocations/datetime.py b/fhirpathpy/engine/invocations/datetime.py index fb881a2..d0a52d0 100644 --- a/fhirpathpy/engine/invocations/datetime.py +++ b/fhirpathpy/engine/invocations/datetime.py @@ -7,8 +7,8 @@ def now(ctx, data): now = constants.nowDate if not now.tzinfo: now = now.astimezone() - isoStr = now.replace(microsecond=0).isoformat() # YYYY-MM-DDThh:mm:ss+zz:zz - constants.now = FP_DateTime(isoStr).getDateTimeMatchStr() + isoStr = now.replace(microsecond=0).isoformat() # YYYY-MM-DDThh:mm:ss.ffffff+zz:zz + constants.now = FP_DateTime(isoStr) return constants.now @@ -23,6 +23,6 @@ def today(ctx, data): def timeOfDay(ctx, data): if not constants.timeOfDay: now = constants.nowDate - isoStr = now.time().replace(microsecond=0).isoformat() # hh:mm:ss - constants.timeOfDay = FP_Time(isoStr).getTimeMatchStr() + isoStr = now.time().replace(microsecond=0).isoformat() # hh:mm:ss.ffffff + constants.timeOfDay = FP_Time(isoStr) return constants.timeOfDay diff --git a/fhirpathpy/engine/nodes.py b/fhirpathpy/engine/nodes.py index 2b453b2..aef059a 100644 --- a/fhirpathpy/engine/nodes.py +++ b/fhirpathpy/engine/nodes.py @@ -300,7 +300,18 @@ def __init__(self, timeStr): self._timeMatchData, self.matchGroupsIndices ) self._precision = len(self._timeAsList) - self._pyTimeObject = datetime.datetime.strptime(self.asStr, "%H:%M:%S").time() + try: + self._pyTimeObject = datetime.datetime.strptime(self.asStr, "%H:%M:%S").time() + except ValueError: + self._pyTimeObject = datetime.datetime.strptime(self.asStr, "%H:%M:%S.%f").time() + + def __str__(self): + if self._pyTimeObject: + time_str = self._pyTimeObject.isoformat() + if "." in time_str: + time_str = time_str[: time_str.index(".") + 4] + return time_str + return self.asStr def getTimeMatchStr(self): return self._timeMatchStr @@ -359,6 +370,11 @@ def __init__(self, dateStr): self._precision = len(self._dateTimeAsList) def __str__(self): + if self._getDateTimeObject(): + iso_str = self._getDateTimeObject().isoformat() + if "." in iso_str: + iso_str = iso_str[: iso_str.index(".") + 4] + iso_str[iso_str.index(".") + 7 :] + return iso_str return self.asStr def getDateTimeMatchStr(self):