@@ 29,30 29,29 @@ import ftputil.stat_cache
Return the expected time shift in seconds assuming the server
uses UTC in its listings and the client uses local time.
Return the expected time shift in seconds.
This is needed because Pure-FTPd meanwhile seems to insist that
the displayed time for files is in UTC.
Unfortunately, the calculation may depend on the timezone of the server,
i. e. the timezone used in directory listings coming from the server.
So, depending on your test environment, you may need to change this
function for your environment. _If_ you need an adapted
`expected_time_shift`, please contact me (my e-mail address is in the
In my particular case, I use Pure-FTPd as FTP server for the integration
tests. At some point, it returned listings in the local timezone of the
server, later it used UTC time, and now it uses the local timezone again.
I wasn't able to find out why or how I can control this.
utc_tuple = time.gmtime()
localtime_tuple = time.localtime()
# To calculate the correct times shift, we need to ignore the
# DST component in the localtime tuple, i. e. set it to 0.
localtime_tuple = localtime_tuple[:-1] + (0,)
time_shift_in_seconds = time.mktime(utc_tuple) - time.mktime(localtime_tuple)
# To be safe, round the above value to units of 3600 s (1 hour).
return round(time_shift_in_seconds / 3600.0) * 3600
# Difference between local times of server and client. If 0.0, server
# and client use the same timezone.
# EXPECTED_TIME_SHIFT = utc_local_time_shift()
# Pure-FTPd seems to have changed its mind (see docstring of
EXPECTED_TIME_SHIFT = 0.0
raw_time_shift = (datetime.datetime.now() - datetime.datetime.utcnow()).seconds
# To be safe, round the above value to units of 900 s (1/4 hours).
return round(raw_time_shift / 900.0) * 900
EXPECTED_TIME_SHIFT = expected_time_shift()