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

Unified Diff: appengine/findit/common/time_util.py

Issue 2480593002: [Predator] Move time_util from common/ to lib/, split code review related part to code_review_util (Closed)
Patch Set: Rebase and fix nits. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/findit/common/test/time_util_test.py ('k') | appengine/findit/crash/crash_pipeline.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/common/time_util.py
diff --git a/appengine/findit/common/time_util.py b/appengine/findit/common/time_util.py
deleted file mode 100644
index 4ef6e8b8a41a167b34bb2a3d5fb090fadf27bf2a..0000000000000000000000000000000000000000
--- a/appengine/findit/common/time_util.py
+++ /dev/null
@@ -1,68 +0,0 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import calendar
-from datetime import datetime
-from datetime import time
-from datetime import timedelta
-
-import pytz
-
-
-def GetUTCNow(): # pragma: no cover.
- """Returns the datetime.utcnow. This is to mock for testing."""
- return datetime.utcnow()
-
-
-def GetUTCNowWithTimezone(): # pragma: no cover.
- """Returns datetime.now but in utc timezone. This is to mock for testing."""
- return datetime.now(pytz.utc)
-
-
-def GetUTCNowTimestamp(): # pragma: no cover.
- """Returns the timestamp for datetime.utcnow. This is to mock for testing."""
- return calendar.timegm(GetUTCNow().timetuple())
-
-
-def RemoveMicrosecondsFromDelta(delta):
- """Returns a timedelta object without microseconds based on delta."""
- return delta - timedelta(microseconds=delta.microseconds)
-
-
-def FormatTimedelta(delta):
- """Returns a string representing the given time delta."""
- if not delta:
- return None
- hours, remainder = divmod(delta.total_seconds(), 3600)
- minutes, seconds = divmod(remainder, 60)
- return '%02d:%02d:%02d' % (hours, minutes, seconds)
-
-
-def FormatDatetime(date):
- """Returns a string representing the given UTC datetime."""
- if not date:
- return None
- else:
- return date.strftime('%Y-%m-%d %H:%M:%S UTC')
-
-
-def FormatDuration(datetime_start, datetime_end):
- """Returns a string representing the given time duration or None."""
- if not datetime_start or not datetime_end:
- return None
- return FormatTimedelta(datetime_end - datetime_start)
-
-
-def GetDatetimeInTimezone(timezone_name, date_time):
- """Returns the datetime.datetime of the given one in the specified timezone.
-
- Args:
- timezone_name (str): The name of any timezone supported by pytz.
- date_time (datetime.datetime): The optional datetime to be converted into
- the new timezone.
-
- Returns:
- A datetime.datetime of the given one in the specified timezone.
- """
- return date_time.astimezone(pytz.timezone(timezone_name))
« no previous file with comments | « appengine/findit/common/test/time_util_test.py ('k') | appengine/findit/crash/crash_pipeline.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698