import time import datetime import http.cookiejar __author__ = 'regu0004' if __name__ == '__main__': # Set expiration date 5 minutes into the future utc_now = datetime.datetime.utcnow() dt = datetime.timedelta(minutes=5) utc_future = utc_now + dt expires = time.mktime(utc_future.timetuple()) name = "test" value = "cookie" cookie = http.cookiejar.Cookie(0, name, value, None, False, "", False, False, "", False, False, expires, False, None, None, {}) # Assert cookie has not expired utc_now = time.mktime(datetime.datetime.utcnow().timetuple()) local_now = time.time() assert not cookie.is_expired(utc_now), "UTC time check failed" # Functions/methods in the http.cookiejar module uses time.time() which # retrieves the epoch time in local time assert not cookie.is_expired(time.time()), "Local time check failed"