From 37e3fd904dfaa65b74b5441792c124191613fe2e Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Sun, 30 Oct 2022 05:22:58 -0700 Subject: [PATCH] Rework getting local-Google time offset (#1572) --- src/gam/__init__.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/gam/__init__.py b/src/gam/__init__.py index d97fd139..60c27012 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -634,28 +634,28 @@ TIME_OFFSET_UNITS = [('day', 86400), ('hour', 3600), ('minute', 60), def getLocalGoogleTimeOffset(testLocation='admin.googleapis.com'): - localUTC = datetime.datetime.now(datetime.timezone.utc) - try: - # we disable SSL verify so we can still get time even if clock - # is way off. This could be spoofed / MitM but we'll fail for those - # situations everywhere else but here. - badhttp = transport.create_http() - badhttp.check_hostname = False - badhttp.disable_ssl_certificate_validation = True - googleUTC = dateutil.parser.parse( - badhttp.request('https://' + testLocation, 'HEAD')[0]['date']) - except (httplib2.ServerNotFoundError, RuntimeError, ValueError) as e: - controlflow.system_error_exit(4, str(e)) - offset = remainder = int(abs((localUTC - googleUTC).total_seconds())) - timeoff = [] - for tou in TIME_OFFSET_UNITS: - uval, remainder = divmod(remainder, tou[1]) - if uval: - timeoff.append(f'{uval} {tou[0]}{"s" if uval != 1 else ""}') - if not timeoff: - timeoff.append('less than 1 second') - nicetime = ', '.join(timeoff) - return (offset, nicetime) + # Try with http first, if time is close (