# HG changeset patch # User Goffi # Date 1663792194 -7200 # Node ID 022ae35a9d8260c43f98ea4162c7550b1032a522 # Parent 4b7106eede0ccd7662bd04bc71ff69b4e0b3d88c tools (utils): helper `parse_xmpp_date` method: This method converts an XMPP date(time) to a unix time rel 372 diff -r 4b7106eede0c -r 022ae35a9d82 sat/tools/utils.py --- a/sat/tools/utils.py Wed Sep 21 22:28:20 2022 +0200 +++ b/sat/tools/utils.py Wed Sep 21 22:29:54 2022 +0200 @@ -163,6 +163,25 @@ ) +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.