def testNsecs(self): ts = DateTime(1192755473000000000L, DateTime.UTC) self.assertEqual(ts.nsecs(DateTime.UTC), 1192755473000000000L) self.assertEqual(ts.nsecs(DateTime.TAI), 1192755506000000000L) self.assertEqual(ts.nsecs(), 1192755506000000000L) self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 54392.040196759262) ts2 = ts self.assertEqual(ts, ts2) ts2 = DateTime(1192755473000000000L, DateTime.UTC) self.assertEqual(ts, ts2) ts2 = DateTime(1234567890000000000L, DateTime.UTC) self.assertNotEqual(ts, ts2)
def testLeapSecond(self): trials = ((45205., 21), (41498.9, 10), (41499.01, 11), (57203.99, 35), (57204.01, 36), (57000., 35), (57210., 36)) for mjd, diff in trials: ts = DateTime(mjd, DateTime.MJD, DateTime.UTC) delta = ts.nsecs(DateTime.TAI) - ts.nsecs(DateTime.UTC) self.assertEqual(delta/1E9, diff)
def testMJD(self): ts = DateTime(45205.125, DateTime.MJD, DateTime.UTC) self.assertEqual(ts.nsecs(DateTime.UTC), 399006000000000000L) self.assertEqual(ts.nsecs(DateTime.TAI), 399006021000000000L) self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 45205.125) self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.TAI), 45205.125 + 21.0/86400.0) # Following interface is deprecated self.assertAlmostEqual(ts.mjd(DateTime.UTC), 45205.125) self.assertAlmostEqual(ts.mjd(DateTime.TAI), 45205.125 + 21.0/86400.0)
def testNsecsDefault(self): ts = DateTime(1192755506000000000L) self.assertEqual(ts.nsecs(DateTime.UTC), 1192755473000000000L) self.assertEqual(ts.nsecs(DateTime.TAI), 1192755506000000000L) self.assertEqual(ts.nsecs(), 1192755506000000000L) self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 54392.040196759262)
def testCrossBoundaryNsecs(self): ts = DateTime(631151998000000000L, DateTime.UTC) self.assertEqual(ts.nsecs(DateTime.UTC), 631151998000000000L) self.assertEqual(ts.nsecs(DateTime.TAI), 631152023000000000L)
def testBoundaryMJD(self): ts = DateTime(47892.0, DateTime.MJD, DateTime.UTC) self.assertEqual(ts.nsecs(DateTime.UTC), 631152000000000000L) self.assertEqual(ts.nsecs(DateTime.TAI), 631152025000000000L) self.assertEqual(ts.get(DateTime.MJD, DateTime.UTC), 47892.0)
def testIsoNoNSecs(self): ts = DateTime("2009-04-02T07:26:39Z") self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233000000000L) self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199000000000L) self.assertEqual(ts.toString(), "2009-04-02T07:26:39.000000000Z")
def testIsoExpanded(self): ts = DateTime("2009-04-02T07:26:39.314159265Z") self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233314159265L) self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199314159265L) self.assertEqual(ts.toString(), "2009-04-02T07:26:39.314159265Z")
def testIsoEpoch(self): ts = DateTime("19700101T000000Z") self.assertEqual(ts.nsecs(DateTime.UTC), 0L) self.assertEqual(ts.toString(), "1970-01-01T00:00:00.000000000Z")