From 9ecf04202f2c8c1150cc0b0dbe0dba87973ed071 Mon Sep 17 00:00:00 2001 From: Justin Boss Date: Tue, 4 Feb 2025 16:39:16 -0500 Subject: [PATCH] Changes for SOLM12-29 --- src/space/times.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/space/times.py b/src/space/times.py index f7e2845..570bdd5 100644 --- a/src/space/times.py +++ b/src/space/times.py @@ -46,28 +46,23 @@ class SpecificTime(datetime.datetime): #Normative :type cls: :param tz: Time zone :type tz: ''' - t = datetime.datetime.now() + t = datetime.datetime.now(tz) return cls(t.year, t.month, t.day, t.hour, t.minute,\ - t.second, t.microsecond) + t.second, t.microsecond, tz) @classmethod def fromStr(cls, strval:str) -> 'SpecificTime': '''Convert from a string representation to a SpecificTime Expected format:YYYY-MM-DDTHH:MM:SS.NNNNNN + May optionally end with a timezone indicator, such as Z. :param cls: Class member :type cls: :param strval: Input time string :type strval: str ''' - strval = strval.strip() - if len(strval) <= 10: - t = datetime.datetime.strptime(strval, '%Y-%m-%d') - elif len(strval) <= 16: - t = datetime.datetime.strptime(strval, '%Y-%m-%dT%H:%M') - else: - t = datetime.datetime.strptime(strval, '%Y-%m-%dT%H:%M:%S.%f') + t = datetime.datetime.fromisoformat(strval) return cls(t.year, t.month, t.day, t.hour, t.minute,\ - t.second, t.microsecond) + t.second, t.microsecond, t.tzinfo) def __str__(self) -> str: '''Converts a SpecificTime to the default string format ''' @@ -183,13 +178,14 @@ def wait(seconds:float) -> None: #Normative ''' time.sleep(seconds) -def waitUntil(specificTime:SpecificTime) -> None: #Normative +def waitUntil(specificTime:datetime.datetime) -> None: #Normative '''Wait for a SpecificTime - returns immediately if time is in the past :param specificTime: Time reference to wait until :type specificTime: SpecificTime ''' - now = SpecificTime.now() + # use same timezone for now as the provided datetime + now = SpecificTime.now(specificTime.tzinfo) delta = (specificTime - now).total_seconds() if delta > 0: time.sleep(delta) -- 2.43.5