Skip to content

Instantly share code, notes, and snippets.

@edgabaldi
Created April 1, 2017 20:52
Show Gist options
  • Save edgabaldi/7265ccea8f455fbcc0d3e56843ce33a4 to your computer and use it in GitHub Desktop.
Save edgabaldi/7265ccea8f455fbcc0d3e56843ce33a4 to your computer and use it in GitHub Desktop.
from unittest import TestCase
import datetime
def d2t(t):
h = int(t)
m = (t * 60) % 60
s = (t * 3600) % 60
a = map(lambda x: int(x), [h, m, s])
return datetime.time(*a)
class D2TTestCase(TestCase):
def test_d2t(self):
self.assertEqual(datetime.time(1,0), d2t(1.0))
self.assertEqual(datetime.time(23, 27), d2t(23.450))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment