コード例 #1
0
 def test_parse(self):
   from epoch import parse as p
   self.assertEqual(p(None), None)
   self.assertEqual(p(1446303600), 1446303600)
   self.assertEqual(p(1446303600.7), 1446303600.7)
   self.assertEqual(p('1446303600'), 1446303600)
   self.assertEqual(p('1446303600.7'), 1446303600.7)
コード例 #2
0
 def test_soy(self):
   import epoch
   from epoch import parseZulu as p
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z')), p('20150101T000000Z'))
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), offset=1), p('20160101T000000Z'))
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), offset=4), p('20190101T000000Z'))
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), offset=-1), p('20140101T000000Z'))
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), offset=-4), p('20110101T000000Z'))
   et = 'America/New_York'
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), tz=et), p('20150101T050000Z'))
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), tz=et, offset=1), p('20160101T050000Z'))
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), tz=et, offset=4), p('20190101T050000Z'))
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), tz=et, offset=-1), p('20140101T050000Z'))
   self.assertEqual(epoch.soy(ts=p('20151031T150000Z'), tz=et, offset=-4), p('20110101T050000Z'))
コード例 #3
0
 def test_parseZulu(self):
   from epoch import parseZulu as p
   self.assertEqual(p('2015-10-31T15:00:00Z'), 1446303600)
   self.assertEqual(p('2015-11-01T15:00:00Z'), 1446390000)
   self.assertEqual(p('2015-11-02T15:00:00Z'), 1446476400)
   self.assertEqual(p('20151031T150000Z'), 1446303600)
   self.assertEqual(p('20151101T150000Z'), 1446390000)
   self.assertEqual(p('20151102T150000Z'), 1446476400)
   self.assertEqual(p('2015-10-31T15:00:00.6Z'), 1446303600.6)
   self.assertEqual(p('2015-10-31T15:00:00.600Z'), 1446303600.6)
   self.assertEqual(p('2015-10-31T15:00:00.006Z'), 1446303600.006)
   self.assertEqual(p('2015-10-31T15:00:00.0006Z'), 1446303600.0006)
   self.assertEqual(p('20151031T150000.6Z'), 1446303600.6)
   self.assertEqual(p('20151031T150000.600Z'), 1446303600.6)
   self.assertEqual(p('20151031T150000.006Z'), 1446303600.006)
   self.assertEqual(p('20151031T150000.0006Z'), 1446303600.0006)
   self.assertEqual(p('20151031T150000.000600000Z'), 1446303600.0006)
   self.assertEqual(p('20151031T150000.000006000Z'), 1446303600.000006)
   # sub-microsecond accuracy not possible (with current `datetime` sys library)
   self.assertEqual(p('20151031T150000.000000600Z'), 1446303600)
コード例 #4
0
 def test_som(self):
   import epoch
   from epoch import parseZulu as p
   self.assertEqual(epoch.som(ts=p('20151031T150000Z')), p('20151001T000000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), offset=1), p('20151101T000000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), offset=2), p('20151201T000000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), offset=-1), p('20150901T000000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), offset=-2), p('20150801T000000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), offset=28), p('20180201T000000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), offset=-28), p('20130601T000000Z'))
   et = 'America/New_York'
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), tz=et), p('20151001T040000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), tz=et, offset=1), p('20151101T040000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), tz=et, offset=2), p('20151201T050000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), tz=et, offset=-1), p('20150901T040000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), tz=et, offset=28), p('20180201T050000Z'))
   self.assertEqual(epoch.som(ts=p('20151031T150000Z'), tz=et, offset=-28), p('20130601T040000Z'))