From 1e4fc213f6361a149e5dbadfcd10cac294890cee Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 21 Sep 2022 22:29:54 +0200 Subject: [PATCH] tools (utils): helper `parse_xmpp_date` method: This method converts an XMPP date(time) to a unix time rel 372 --- sat/tools/utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sat/tools/utils.py b/sat/tools/utils.py index 2f9cb368..cf40c517 100644 --- a/sat/tools/utils.py +++ b/sat/tools/utils.py @@ -163,6 +163,25 @@ def xmpp_date( ) +def parse_xmpp_date( + xmpp_date_str: str, + with_time: bool = True +) -> float: + """Get timestamp from XEP-0082 datetime + + @param xmpp_date_str: XEP-0082 formatted datetime or time + @param with_time: if True, ``xmpp_date_str`` must be a datetime, otherwise if must be + a time profile. + @return: datetime converted to unix time + """ + if with_time: + dt = xmpp_datetime.parse_datetime(xmpp_date_str) + else: + dt = xmpp_datetime.parse_date(xmpp_date_str) + + return time.mktime(dt.timetuple()) + + def generatePassword(vocabulary=None, size=20): """Generate a password with random characters.