Skip to content

Commit ac23fa4

Browse files
committed
implement now #12
1 parent 218a705 commit ac23fa4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/underscore.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import functools
66
import random
7+
import time
78
from threading import Timer
89

910

@@ -1311,6 +1312,9 @@ def times(self, func, *args):
13111312

13121313
return self._wrap(func)
13131314

1315+
def now(self):
1316+
return self._wrap(time.time())
1317+
13141318
def random(self, max_number=None):
13151319
""" Return a random integer between min and max (inclusive).
13161320
"""

tests/test_utility.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
init() # will let you import modules from upper folder
44
from src.underscore import _
55
import math
6-
6+
import time
77

88
class TestUtility(unittest.TestCase):
99

@@ -40,6 +40,10 @@ def check2(*args):
4040
result = _.every(array, check2)
4141
self.assertTrue(result, "should produce a random number when passed max_number")
4242

43+
def test_now(self):
44+
diff = _.now() - time.time()
45+
self.assertTrue(diff <= 0 and diff > -5, 'Produces the correct time in milliseconds')
46+
4347
def test_uniqueId(self):
4448
ns = self.Namespace()
4549
ns.ids = []

0 commit comments

Comments
 (0)