diff --git a/win32/Lib/win32timezone.py b/win32/Lib/win32timezone.py index fdd71c8557..677ad6a69d 100644 --- a/win32/Lib/win32timezone.py +++ b/win32/Lib/win32timezone.py @@ -758,7 +758,7 @@ def local(class_): registry. >>> localTZ = TimeZoneInfo.local() >>> now_local = datetime.datetime.now(localTZ) - >>> now_UTC = datetime.datetime.utcnow() + >>> now_UTC = datetime.datetime.utcnow() # deprecated >>> (now_UTC - now_local) < datetime.timedelta(seconds = 5) Traceback (most recent call last): ... @@ -769,6 +769,11 @@ def local(class_): Now one can compare the results of the two offset aware values >>> (now_UTC - now_local) < datetime.timedelta(seconds = 5) True + + Or use the newer `datetime.timezone.utc` + >>> now_UTC = datetime.datetime.now(datetime.timezone.utc) + >>> (now_UTC - now_local) < datetime.timedelta(seconds = 5) + True """ code, info = TimeZoneDefinition.current() # code is 0 if daylight savings is disabled or not defined @@ -895,22 +900,30 @@ def _enumerate_reg(key, func): pass -def utcnow(): +def utcnow() -> datetime.datetime: """ Return the UTC time now with timezone awareness as enabled by this module >>> now = utcnow() + + >>> (now - datetime.datetime.now(datetime.timezone.utc)) < datetime.timedelta(seconds = 5) + True + >>> type(now.tzinfo) is TimeZoneInfo + True """ - now = datetime.datetime.utcnow() - now = now.replace(tzinfo=TimeZoneInfo.utc()) - return now + return datetime.datetime.now(TimeZoneInfo.utc()) -def now(): +def now() -> datetime.datetime: """ Return the local time now with timezone awareness as enabled by this module >>> now_local = now() + + >>> (now_local - datetime.datetime.now(datetime.timezone.utc)) < datetime.timedelta(seconds = 5) + True + >>> type(now_local.tzinfo) is TimeZoneInfo + True """ return datetime.datetime.now(TimeZoneInfo.local())