Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: appengine/findit/common/time_util.py

Issue 2391063002: [Findit] Fix flaky tests due to importing pytz. (Closed)
Patch Set: Fix nit. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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))
OLDNEW
« no previous file with comments | « appengine/findit/common/test/time_util_test.py ('k') | appengine/findit/waterfall/flake/recursive_flake_pipeline.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698