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

Side by Side Diff: scripts/slave/recipe_modules/time/api.py

Issue 1241323004: Cross-repo recipe package system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Roll to latest recipes-py Created 5 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from recipe_engine import recipe_api
6
7 import datetime
8 import time
9
10 class TimeApi(recipe_api.RecipeApi):
11 def __init__(self, **kwargs):
12 super(TimeApi, self).__init__(**kwargs)
13 self._fake_time = None
14 self._fake_step = None
15 if self._test_data.enabled:
16 self._fake_time = self._test_data.get('seed', 1337000000.0)
17 self._fake_step = self._test_data.get('step', 1.5)
18
19 def time(self):
20 """Return current timestamp as a float number of seconds since epoch."""
21 if self._test_data.enabled:
22 self._fake_time += self._fake_step
23 return self._fake_time
24 else: # pragma: no cover
25 return time.time()
26
27 def utcnow(self):
28 """Return current UTC time as a datetime.datetime."""
29 if self._test_data.enabled:
30 self._fake_time += self._fake_step
31 return datetime.datetime.utcfromtimestamp(self._fake_time)
32 else: # pragma: no cover
33 return datetime.datetime.utcnow()
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/time/__init__.py ('k') | scripts/slave/recipe_modules/time/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698