| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import calendar | 5 import calendar |
| 6 from datetime import datetime | 6 from datetime import datetime |
| 7 from datetime import time | 7 from datetime import time |
| 8 from datetime import timedelta | 8 from datetime import timedelta |
| 9 | 9 |
| 10 import pytz | 10 import pytz |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 return '%02d:%02d:%02d' % (hours, minutes, seconds) | 38 return '%02d:%02d:%02d' % (hours, minutes, seconds) |
| 39 | 39 |
| 40 | 40 |
| 41 def FormatDatetime(date): | 41 def FormatDatetime(date): |
| 42 if not date: | 42 if not date: |
| 43 return None | 43 return None |
| 44 else: | 44 else: |
| 45 return date.strftime('%Y-%m-%d %H:%M:%S UTC') | 45 return date.strftime('%Y-%m-%d %H:%M:%S UTC') |
| 46 | 46 |
| 47 | 47 |
| 48 def GetDatetimeInTimezone(timezone_name, date_time=None): | 48 def GetDatetimeInTimezone(timezone_name, date_time): |
| 49 """Returns the datetime.datetime of the given one in the specified timezone. | 49 """Returns the datetime.datetime of the given one in the specified timezone. |
| 50 | 50 |
| 51 Args: | 51 Args: |
| 52 timezone_name (str): The name of any timezone supported by pytz. | 52 timezone_name (str): The name of any timezone supported by pytz. |
| 53 date_time (datetime.datetime): The optional datetime to be converted into | 53 date_time (datetime.datetime): The optional datetime to be converted into |
| 54 the new timezone. If not given, default to UTC now. | 54 the new timezone. |
| 55 | 55 |
| 56 Returns: | 56 Returns: |
| 57 A datetime.datetime of the given one in the specified timezone. | 57 A datetime.datetime of the given one in the specified timezone. |
| 58 """ | 58 """ |
| 59 date_time = date_time or GetUTCNowWithTimezone() | |
| 60 return date_time.astimezone(pytz.timezone(timezone_name)) | 59 return date_time.astimezone(pytz.timezone(timezone_name)) |
| OLD | NEW |