Skip to content

Commit

Permalink
Update FP_Time and FP_DateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
atuonufure committed Aug 18, 2023
1 parent 127416e commit 2e8fed5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 4 additions & 4 deletions fhirpathpy/engine/invocations/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
18 changes: 17 additions & 1 deletion fhirpathpy/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2e8fed5

Please sign in to comment.