# information regarding copyright ownership.
from collections import defaultdict
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from time import sleep
import os
import isctest
-# ISO datetime format without msec
-FMT = "%Y-%m-%dT%H:%M:%SZ"
+# ISO datetime format without msec (the %z directive parses the trailing "Z"
+# as UTC, yielding timezone-aware datetimes)
+FMT = "%Y-%m-%dT%H:%M:%S%z"
# The constants were taken from BIND 9 source code (lib/dns/zone.c)
max_refresh = timedelta(seconds=2419200) # 4 weeks
max_expires = timedelta(seconds=14515200) # 24 weeks
-dayzero = datetime.utcfromtimestamp(0).replace(microsecond=0)
+dayzero = datetime.fromtimestamp(0, timezone.utc).replace(microsecond=0)
# Wait for the secondary zone files to appear to extract their mtime
MAX_SECONDARY_ZONE_WAITTIME_SEC = 5
def check_zone_timers(loaded, expires, refresh, loaded_exp):
- now = datetime.utcnow().replace(microsecond=0)
+ now = datetime.now(timezone.utc).replace(microsecond=0)
# Sanity checks the zone timers values
if expires is not None:
check_expires(expires, now, now + max_expires)
except FileNotFoundError:
return dayzero
- mtime = datetime.utcfromtimestamp(si.st_mtime).replace(microsecond=0)
+ mtime = datetime.fromtimestamp(si.st_mtime, timezone.utc).replace(microsecond=0)
return mtime