Changeset 1932:3cbfe0a457db


Ignore:
Timestamp:
Apr 11, 2020, 9:43:18 PM (16 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
amend_source:
b561e1afe618afaaa76167a062f4aaca0740b0dc
Message:
Use `datetime` API instead of `time` API

The `datetime` API is easier to use. Could be that this test code was
written when `datetime` wasn't a part of the Python standard library.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/todo.txt

    r1930 r1932  
    11Planned:
    22
    3 - Use `datetime` module instead of `time` module
    43- Add helper routines `server_time_from_client_time` and
    54  `client_time_from_server_time`
  • test/test_host.py

    r1898 r1932  
    659659            # is a year too far in the past. The `synchronize_times`
    660660            # method needs to deal with this and add the year "back".
    661             # I don't think it's a bug in `parse_unix_time` because the
    662             # method should work once the time shift is set correctly.
    663             local_time = time.localtime()
    664             local_time_with_wrong_year = (local_time.tm_year - 1,) + local_time[1:]
    665             presumed_server_time = (
    666                 time.mktime(local_time_with_wrong_year) + presumed_time_shift
     661            # I don't think this is a bug in `parse_unix_time` because
     662            # the method should work once the time shift is set correctly.
     663            client_time = datetime.datetime.utcnow().replace(
     664                tzinfo=datetime.timezone.utc
    667665            )
    668             host.path.set_mtime(presumed_server_time)
     666            presumed_server_time = client_time.replace(
     667                year=client_time.year - 1
     668            ) + datetime.timedelta(seconds=presumed_time_shift)
     669            host.path.set_mtime(presumed_server_time.timestamp())
    669670            host.synchronize_times()
    670671            assert host.time_shift() == presumed_time_shift
Note: See TracChangeset for help on using the changeset viewer.