From ea0b891a456f8462ed67a4277b7ed6c74f5962e8 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 8 Aug 2020 15:34:46 +0100 Subject: [PATCH] {Profile} use UTC timezone when converting expiration timestamps to strings datetime.fromtimestamp will use the machine's locale timezone by default, causing expiration timestamps to vary depending on the local setting. Use UTC to ensure they are stable. --- src/azure-cli/azure/cli/command_modules/profile/custom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/profile/custom.py b/src/azure-cli/azure/cli/command_modules/profile/custom.py index 6d3f98fce81..5377b851328 100644 --- a/src/azure-cli/azure/cli/command_modules/profile/custom.py +++ b/src/azure-cli/azure/cli/command_modules/profile/custom.py @@ -79,8 +79,9 @@ def get_access_token(cmd, subscription=None, resource=None, resource_type=None, # Unify to ISO `expiresOn`, like "2020-06-30 06:14:41" if 'expires_on' in token_entry: from datetime import datetime + from pytz import utc # https://docs.python.org/3.8/library/datetime.html#strftime-and-strptime-format-codes - token_entry['expiresOn'] = datetime.fromtimestamp(int(token_entry['expires_on']))\ + token_entry['expiresOn'] = datetime.fromtimestamp(int(token_entry['expires_on']), utc)\ .strftime("%Y-%m-%d %H:%M:%S.%f") result = {