comparison sat/tools/utils.py @ 3878:32087d7c25d4

tools (datetime, utils): fix incorrect use of naive object: `tools.datetime.format_datetime` was expecting aware datetime objects while `tools.utils.xmpp_date` was returning naive datetime objects. A check has been added to the former one, and latter one has been modified to return aware datetime objects.
author Goffi <goffi@goffi.org>
date Wed, 31 Aug 2022 13:11:26 +0200
parents 00212260f659
children 46930301f0c1
comparison
equal deleted inserted replaced
3877:00212260f659 3878:32087d7c25d4
150 this function redirects to the functions in the :mod:`sat.tools.datetime` module 150 this function redirects to the functions in the :mod:`sat.tools.datetime` module
151 @param timestamp(None, float): posix timestamp. If None current time will be used 151 @param timestamp(None, float): posix timestamp. If None current time will be used
152 @param with_time(bool): if True include the time 152 @param with_time(bool): if True include the time
153 @return(unicode): XEP-0082 formatted date and time 153 @return(unicode): XEP-0082 formatted date and time
154 """ 154 """
155 dtime = datetime.datetime.utcfromtimestamp( 155 dtime = datetime.datetime.fromtimestamp(
156 time.time() if timestamp is None else timestamp 156 time.time() if timestamp is None else timestamp,
157 datetime.timezone.utc
157 ) 158 )
158 159
159 return format_datetime(dtime) if with_time else format_date(dtime.date()) 160 return format_datetime(dtime) if with_time else format_date(dtime.date())
160 161
161 162