def test_TM_offset(self): time = datetime.strptime('0101', '%H%M') time2 = datetime.strptime('010111.1110', '%H%M%S.%f') tm = TM(time, out_format='%H%M', offset='+0100') tm2 = TM(time2, out_format='%H%M%S.%f', offset='-0300') TM(time, offset='+0000') TM(time, offset='-0000') TM(time, offset='+1200') TM(time, offset='-1200') self.assertEqual(tm.offset, '+0100') self.assertEqual(tm2.offset, '-0300') self.assertEqual(tm.to_er7(), '0101+0100') #check if a space is needed between time and offset, or not self.assertEqual(tm2.to_er7(), '010111.1110-0300')
def test_DTM(self): dtime = datetime.strptime('2013', '%Y') dtime1 = datetime.strptime('201307', '%Y%m') dtime2 = datetime.strptime('20130715', '%Y%m%d') dtime3 = datetime.strptime('01', '%H') dtime4 = datetime.strptime('0101', '%H%M') dtime5 = datetime.strptime('010111', '%H%M%S') dtime6 = datetime.strptime('010111.1110', '%H%M%S.%f') dtime7 = datetime.strptime('20130715010111.1110', '%Y%m%d%H%M%S.%f') dtm = DTM(dtime, out_format='%Y') dtm1 = DTM(dtime1, out_format='%Y%m') dtm2 = DTM(dtime2, out_format='%Y%m%d') dtm3 = TM(dtime3, out_format='%H') dtm4 = TM(dtime4, out_format='%H%M') dtm5 = TM(dtime5, out_format='%H%M%S') dtm6 = TM(dtime6, out_format='%H%M%S.%f') dtm7 = DTM(dtime7, out_format='%Y%m%d%H%M%S.%f') self.assertEqual(dtm.classname, 'DTM') self.assertEqual(dtm.to_er7(), '2013') self.assertEqual(dtm1.to_er7(), '201307') self.assertEqual(dtm2.to_er7(), '20130715') self.assertEqual(dtm3.to_er7(), '01') self.assertEqual(dtm4.to_er7(), '0101') self.assertEqual(dtm5.to_er7(), '010111') self.assertEqual(dtm6.to_er7(), '010111.1110') self.assertEqual(dtm7.to_er7(), '20130715010111.1110')
def test_DTM(self): dtime = datetime.strptime('2013', '%Y') dtime1 = datetime.strptime('201307', '%Y%m') dtime2 = datetime.strptime('20130715', '%Y%m%d') dtime3 = datetime.strptime('01', '%H') dtime4 = datetime.strptime('0101', '%H%M') dtime5 = datetime.strptime('010111', '%H%M%S') dtime6 = datetime.strptime('010111.111', '%H%M%S.%f') dtime7 = datetime.strptime('20130715010111.111', '%Y%m%d%H%M%S.%f') dtm = DTM(dtime, format='%Y') dtm1 = DTM(dtime1, format='%Y%m') dtm2 = DTM(dtime2, format= '%Y%m%d') dtm3 = TM(dtime3, format= '%H') dtm4 = TM(dtime4, format= '%H%M') dtm5 = TM(dtime5, format= '%H%M%S') dtm6 = TM(dtime6, format= '%H%M%S.%f') dtm7 = DTM(dtime7, format= '%Y%m%d%H%M%S.%f') self.assertEqual(dtm.classname, 'DTM') self.assertEqual(dtm.to_er7(), datetime.strftime(dtime, dtm.format)) self.assertEqual(dtm1.to_er7(), datetime.strftime(dtime1, dtm1.format)) self.assertEqual(dtm2.to_er7(), datetime.strftime(dtime2, dtm2.format)) self.assertEqual(dtm3.to_er7(), datetime.strftime(dtime3, dtm3.format)) self.assertEqual(dtm4.to_er7(), datetime.strftime(dtime4, dtm4.format)) self.assertEqual(dtm5.to_er7(), datetime.strftime(dtime5, dtm5.format)) self.assertEqual(dtm6.to_er7(), datetime.strftime(dtime6, dtm6.format)) self.assertEqual(dtm7.to_er7(), datetime.strftime(dtime7, dtm7.format)) self.assertEqual(dtm7.to_er7(), datetime.strftime(dtime7, dtm7.format))
def test_TM_offset(self): time = datetime.strptime('0101', '%H%M') time2 = datetime.strptime('010111.1110', '%H%M%S.%f') tm = TM(time, out_format='%H%M', offset='+0100') tm2 = TM(time2, out_format='%H%M%S.%f', offset='-0300') TM(time, offset='+0000') TM(time, offset='-0000') TM(time, offset='+1200') TM(time, offset='-1200') self.assertEqual(tm.offset, '+0100') self.assertEqual(tm2.offset, '-0300') self.assertEqual( tm.to_er7(), '0101+0100' ) # check if a space is needed between time and offset, or not self.assertEqual(tm2.to_er7(), '010111.1110-0300')
def test_TM_custom_microsec_precision(self): time = datetime.strptime('011959.1234', '%H%M%S.%f') tm = TM(time, microsec_precision=1) self.assertEqual(tm.to_er7(), '011959.1') tm = TM(time, microsec_precision=2) self.assertEqual(tm.to_er7(), '011959.12') tm = TM(time, microsec_precision=3) self.assertEqual(tm.to_er7(), '011959.123') tm = TM(time, microsec_precision=4) self.assertEqual(tm.to_er7(), '011959.1234')
def test_TM(self): time = datetime.strptime('01', '%H') time1 = datetime.strptime('0101', '%H%M') time2 = datetime.strptime('010111', '%H%M%S') time3 = datetime.strptime('010111.1110', '%H%M%S.%f') tm = TM(time, out_format='%H') tm1 = TM(time1, out_format='%H%M') tm2 = TM(time2, out_format='%H%M%S') tm3 = TM(time3, out_format='%H%M%S.%f') self.assertEqual(tm.classname, 'TM') self.assertEqual(tm.to_er7(), '01') self.assertEqual(tm1.to_er7(), '0101') self.assertEqual(tm2.to_er7(), '010111') self.assertEqual(tm3.to_er7(), '010111.1110')
def test_TM(self): time = datetime.strptime('01', '%H') time1 = datetime.strptime('0101', '%H%M') time2 = datetime.strptime('010111', '%H%M%S') time3 = datetime.strptime('010111.111', '%H%M%S.%f') tm = TM(time, format='%H') tm1 = TM(time1, format='%H%M') tm2 = TM(time2, format='%H%M%S') tm3 = TM(time3, format='%H%M%S.%f') self.assertEqual(tm.classname, 'TM') self.assertEqual(tm.to_er7(), datetime.strftime(time, tm.format)) self.assertEqual(tm1.to_er7(), datetime.strftime(time1, tm1.format)) self.assertEqual(tm2.to_er7(), datetime.strftime(time2, tm2.format)) self.assertEqual(tm3.to_er7(), datetime.strftime(time3, tm3.format))
def test_TM_default_format(self): time = datetime.strptime('010111.1110', '%H%M%S.%f') tm = TM(time) self.assertEqual(tm.to_er7(), '010111.1110')