Changeset 1928:7e2299845b86


Ignore:
Timestamp:
Apr 11, 2020, 8:33:31 PM (16 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Change `utc_local_time_shift` to `expected_time_shift`

Replace the function `utc_local_time_shift` with
`expected_time_shift`. The purpose of both functions is very similar,
to set the constant `EXPECTED_TIME_SHIFT`. I changed the name because
the time shift is now relative to UTC, not to the local time of the
client. Therefore, the function old name would be confusing.

ticket: 134
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_real_ftp.py

    r1927 r1928  
    3030
    3131
    32 def utc_local_time_shift():
     32def expected_time_shift():
    3333    """
    34     Return the expected time shift in seconds assuming the server
    35     uses UTC in its listings and the client uses local time.
    36 
    37     This is needed because Pure-FTPd meanwhile seems to insist that
    38     the displayed time for files is in UTC.
     34    Return the expected time shift in seconds.
     35
     36    Unfortunately, the calculation may depend on the timezone of the server,
     37    i. e. the timezone used in directory listings coming from the server.
     38
     39    So, depending on your test environment, you may need to change this
     40    function for your environment. _If_ you need an adapted
     41    `expected_time_shift`, please contact me (my e-mail address is in the
     42    ftputil documentation).
     43
     44    In my particular case, I use Pure-FTPd as FTP server for the integration
     45    tests. At some point, it returned listings in the local timezone of the
     46    server, later it used UTC time, and now it uses the local timezone again.
     47    I wasn't able to find out why or how I can control this.
    3948    """
    40     utc_tuple = time.gmtime()
    41     localtime_tuple = time.localtime()
    42     # To calculate the correct times shift, we need to ignore the
    43     # DST component in the localtime tuple, i. e. set it to 0.
    44     localtime_tuple = localtime_tuple[:-1] + (0,)
    45     time_shift_in_seconds = time.mktime(utc_tuple) - time.mktime(localtime_tuple)
    46     # To be safe, round the above value to units of 3600 s (1 hour).
    47     return round(time_shift_in_seconds / 3600.0) * 3600
    48 
    49 
    50 # Difference between local times of server and client. If 0.0, server
    51 # and client use the same timezone.
    52 # EXPECTED_TIME_SHIFT = utc_local_time_shift()
    53 # Pure-FTPd seems to have changed its mind (see docstring of
    54 # `utc_local_time_shift`).
    55 EXPECTED_TIME_SHIFT = 0.0
     49    raw_time_shift = (datetime.datetime.now() - datetime.datetime.utcnow()).seconds
     50    # To be safe, round the above value to units of 900 s (1/4 hours).
     51    return round(raw_time_shift / 900.0) * 900
     52
     53
     54EXPECTED_TIME_SHIFT = expected_time_shift()
    5655
    5756
Note: See TracChangeset for help on using the changeset viewer.