comparison sat/tools/utils.py @ 3898:022ae35a9d82

tools (utils): helper `parse_xmpp_date` method: This method converts an XMPP date(time) to a unix time rel 372
author Goffi <goffi@goffi.org>
date Wed, 21 Sep 2022 22:29:54 +0200
parents 46930301f0c1
children 8179cff7ef5c
comparison
equal deleted inserted replaced
3897:4b7106eede0c 3898:022ae35a9d82
159 159
160 return ( 160 return (
161 xmpp_datetime.format_datetime(dtime) if with_time 161 xmpp_datetime.format_datetime(dtime) if with_time
162 else xmpp_datetime.format_date(dtime.date()) 162 else xmpp_datetime.format_date(dtime.date())
163 ) 163 )
164
165
166 def parse_xmpp_date(
167 xmpp_date_str: str,
168 with_time: bool = True
169 ) -> float:
170 """Get timestamp from XEP-0082 datetime
171
172 @param xmpp_date_str: XEP-0082 formatted datetime or time
173 @param with_time: if True, ``xmpp_date_str`` must be a datetime, otherwise if must be
174 a time profile.
175 @return: datetime converted to unix time
176 """
177 if with_time:
178 dt = xmpp_datetime.parse_datetime(xmpp_date_str)
179 else:
180 dt = xmpp_datetime.parse_date(xmpp_date_str)
181
182 return time.mktime(dt.timetuple())
164 183
165 184
166 def generatePassword(vocabulary=None, size=20): 185 def generatePassword(vocabulary=None, size=20):
167 """Generate a password with random characters. 186 """Generate a password with random characters.
168 187