def testPTPrand(self): t = ptptime.randptptime() if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t)) d = {'year': 2012, 'leapyear': False} t = ptptime.randptptime(year=d['year']) if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t)) checkAttributes(t, d) t = ptptime.randptptime(max_year=d['year']) if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t))
def testPTPnow(self): microsecond = 999999 while microsecond > 499999: t = datetime.datetime.now() microsecond = t.microsecond d = {'year': t.year, 'month': t.month, 'day': t.day, 'hour': t.hour, 'minute': t.minute, 'second': t.second, 'nanosecond': 0, 'leapyear': False } t = ptptime.ptptime.now() checkAttributes(t, d)
def testPTPdateTime(self): d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + datetime.timedelta(days=1) d['day'] = 13 checkAttributes(tn, d) if not str(tn) == "1972-11-13 16:24:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) tn = t - datetime.timedelta(days=1) d['day'] = 11 checkAttributes(tn, d) if not str(tn) == "1972-11-11 16:24:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn))
def testFromPtp(self): t = ptptime.timefromptp(0x0000000000000000) if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t)) d = {'year': 1970, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': 0} checkAttributes(t, d) t = ptptime.timefromptp(0x386d438000000000) if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t)) d = {'year': 2000, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': 0} checkAttributes(t, d) t = ptptime.timefromptp(0x386d43A000000000, leapyear=-1) if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t)) d = {'year': 2000, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': -1} checkAttributes(t, d) t = ptptime.timefromptp(0x386d438100000000, leapyear=1) if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t)) d = {'year': 2000, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': 1} checkAttributes(t, d) t = ptptime.timefromptp(0x14b0823f3b9ac618) if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t)) d = {'year': 1980, 'month': 12 , 'day': 31, 'hour': 11, 'minute': 59, 'second': 59, 'microsecond': 999999, 'nanosecond': 0, 'leapyear': 0} checkAttributes(t, d) t = ptptime.timefromptp(0x14b12aff3b9ac618) if not isinstance(t, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(t)) d = {'year': 1980, 'month': 12 , 'day': 31, 'hour': 23, 'minute': 59, 'second': 59, 'microsecond': 999999, 'nanosecond': 0, 'leapyear': 0} checkAttributes(t, d) d = {'year': 1981, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) t = t - ptptime.timedelta(microseconds=1) d = {'year': 1980, 'month': 12 , 'day': 31, 'hour': 23, 'minute': 59, 'second': 59, 'microsecond': 999999, 'nanosecond': 0, 'leapyear': 0} checkAttributes(t, d) expected = 0x14b12aff3b9ac618 if not t.ptp == expected: assert False, "Incorrect PTP value: 0x{0:016x}, expected 0x{1:016x}".format(t.ptp, expected) t = t - ptptime.timedelta(hours=12) d = {'year': 1980, 'month': 12 , 'day': 31, 'hour': 11, 'minute': 59, 'second': 59, 'microsecond': 999999, 'nanosecond': 0, 'leapyear': 0} checkAttributes(t, d) expected = 0x14b0823f3b9ac618 if not t.ptp == expected: assert False, "Incorrect PTP value: 0x{0:016x}, expected 0x{1:016x}".format(t.ptp, expected)
def testPTPAddition(self): d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(days=1) d['day'] = 13 checkAttributes(tn, d) if not str(tn) == "1972-11-13 16:24:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(hours=1) d['hour'] = 17 checkAttributes(tn, d) if not str(tn) == "1972-11-12 17:24:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(minutes=1) d['minute'] = 25 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:25:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(seconds=1) d['second'] = 35 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:35.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(microseconds=1) d['microsecond'] = 123457 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123457:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 1 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123456:001": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=999) d['nanosecond'] = 999 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123456:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=1000) d['nanosecond'] = 0 d['microsecond'] = 123457 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123457:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=1001) d['nanosecond'] = 1 d['microsecond'] = 123457 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123457:001": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 999999, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=1001) d['nanosecond'] = 1 d['microsecond'] = 0 d['second'] = 35 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:35.000000:001": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 1, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'], d['nanosecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 2 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123456:002": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 501, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'], d['nanosecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=501) d['nanosecond'] = 2 d['microsecond'] = 123457 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123457:002": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 1, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'], nanosecond=d['nanosecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 2 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123456:002": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 501, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'], nanosecond=d['nanosecond']) checkAttributes(t, d) tn = t + ptptime.timedelta(nanoseconds=501) d['nanosecond'] = 2 d['microsecond'] = 123457 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123457:002": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn))
def testPTPCreation(self): d = {'year': 2000, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) if not str(t) == "2000-1-1 00:00:00.000000:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) if not t.ptp == 0x386d438000000000: assert False, "Incorrect PTP value: '0x{0:016x}'".format(t.ptp) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) if not str(t) == "1972-11-12 16:24:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) if not t.ptp == 0x0563e7c2075bca00: assert False, "Incorrect PTP value: '0x{0:016x}'".format(t.ptp) if not t.sbi == 0x04160317cb2434123456: assert False, "Incorrect SBI value: '0x{0:020x}'".format(t.sbi) if not t.iena == 0x18e296f216c0: assert False, "Incorrect IENA value: '0x{0:012x}'".format(t.iena) # x = t.printPTP() # if not x == "0x0563e7c2075bca00": # assert False, "Incorrect printPTP: '0x{0:016x}'".format(t.ptp) # d['nanosecond'] = 235 t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) if not str(t) == "1972-11-12 16:24:34.123456:235": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) if not t.ptp == 0x0563e7c2075bcaeb: assert False, "Incorrect PTP value: '0x{0:016x}'".format(t.ptp) if not t.sbi == 0x04160317cb2434123456: assert False, "Incorrect SBI value: '0x{0:020x}'".format(t.sbi) if not t.iena == 0x18e296f216c0: assert False, "Incorrect IENA value: '0x{0:012x}'".format(t.iena) d['nanosecond'] = 123 t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],nanosecond=d['nanosecond']) checkAttributes(t, d) if not str(t) == "1972-11-12 16:24:34.123456:123": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) if not t.ptp == 0x0563e7c2075bca7b: assert False, "Incorrect PTP value: '0x{0:016x}'".format(t.ptp) if not t.sbi == 0x04160317cb2434123456: assert False, "Incorrect SBI value: '0x{0:020x}'".format(t.sbi) if not t.iena == 0x18e296f216c0: assert False, "Incorrect IENA value: '0x{0:012x}'".format(t.iena) d['year'] = 2008 d['leapyear'] = True d['nanosecond'] = 0 t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'], leapyear=d['leapyear']) checkAttributes(t, d) if not str(t) == "2008-11-12 16:24:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) if not t.ptp == 0x491b0343075bca00: assert False, "Incorrect PTP value: '0x{0:016x}'".format(t.ptp) if not t.sbi == 0x377303174b2434123456: assert False, "Incorrect SBI value: '0x{0:020x}'".format(t.sbi) if not t.iena == 0x18e297015900: assert False, "Incorrect IENA value: '0x{0:012x}'".format(t.iena) d['nanosecond'] = 235 t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond'], leapyear=d['leapyear']) checkAttributes(t, d) if not str(t) == "2008-11-12 16:24:34.123456:235": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) if not t.ptp == 0x491b0343075bcaeb: assert False, "Incorrect PTP value: '0x{0:016x}'".format(t.ptp) if not t.sbi == 0x377303174b2434123456: assert False, "Incorrect SBI value: '0x{0:020x}'".format(t.sbi) if not t.iena == 0x18e297015900: assert False, "Incorrect IENA value: '0x{0:012x}'".format(t.iena) d['nanosecond'] = 123 t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],nanosecond=d['nanosecond'], leapyear=d['leapyear']) checkAttributes(t, d) if not str(t) == "2008-11-12 16:24:34.123456:123": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) if not t.ptp == 0x491b0343075bca7b: assert False, "Incorrect PTP value: '0x{0:016x}'".format(t.ptp) if not t.sbi == 0x377303174b2434123456: assert False, "Incorrect SBI value: '0x{0:020x}'".format(t.sbi) if not t.iena == 0x18e297015900: assert False, "Incorrect IENA value: '0x{0:012x}'".format(t.iena)
def testPTPutcfromtimestamp(self): x0 = ptptime.ptptime(1970,1,1,0,0,0,0,0) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'year': 1970, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} checkAttributes(x1, d) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0} checkAttributes(x2, d) expected = 0 if not expected == x0.total_seconds: assert False, "Incorrect Total Seconds: '{0}' expected '{1}'".format(x0.total_seconds, expected) x0 = ptptime.ptptime(1970,1,1,0,1,0,0,0) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 x0 = ptptime.ptptime(1970,1,1,0,0,1,0,0) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'year': 1970, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} checkAttributes(x1, d) d = {'days': 0, 'seconds': 1, 'microseconds': 0, 'nanoseconds': 0} checkAttributes(x2, d) expected = 1 if not expected == x0.total_seconds: assert False, "Incorrect Total Seconds: '{0}' expected '{1}'".format(x0.total_seconds, expected) x0 = ptptime.ptptime(1970,1,1,0,1,0,0,0) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'days': 0, 'seconds': 60, 'microseconds': 0, 'nanoseconds': 0} checkAttributes(x2, d) expected = 60 if not expected == x0.total_seconds: assert False, "Incorrect Total Seconds: '{0}' expected '{1}'".format(x0.total_seconds, expected) x0 = ptptime.ptptime(1970,1,1,1,0,0,0,0) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'days': 0, 'seconds': 3600, 'microseconds': 0, 'nanoseconds': 0} checkAttributes(x2, d) expected = 3600 if not expected == x0.total_seconds: assert False, "Incorrect Total Seconds: '{0}' expected '{1}'".format(x0.total_seconds, expected) x0 = ptptime.ptptime(1970,1,2,0,0,0,0,0) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'days': 1, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0} checkAttributes(x2, d) expected = 86400 if not expected == x0.total_seconds: assert False, "Incorrect Total Seconds: '{0}' expected '{1}'".format(x0.total_seconds, expected) x0 = ptptime.ptptime(1970,2,1,0,0,0,0,0) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'days': 31, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0} checkAttributes(x2, d) expected = 2678400 if not expected == x0.total_seconds: assert False, "Incorrect Total Seconds: '{0}' expected '{1}'".format(x0.total_seconds, expected) x0 = ptptime.ptptime(1971,1,1,0,0,0,0,0) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'days': 365, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0} checkAttributes(x2, d) expected = 31536000 if not expected == x0.total_seconds: assert False, "Incorrect Total Seconds: '{0}' expected '{1}'".format(x0.total_seconds, expected) x0 = ptptime.ptptime(1971,2,2,1,1,1,1,1) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'year': 1970, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} checkAttributes(x1, d) d = {'days': 397, 'seconds': 3661, 'microseconds': 1, 'nanoseconds': 1} checkAttributes(x2, d) x0 = ptptime.ptptime(1971,2,2,1,1,1,1,1001) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'year': 1970, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} checkAttributes(x1, d) d = {'days': 397, 'seconds': 3661, 'microseconds': 2, 'nanoseconds': 1} checkAttributes(x2, d) x0 = ptptime.ptptime(1971,2,2,1,1,1,999999,1001) x1 = ptptime.ptptime.utcfromtimestamp(0) x2 = x0 - x1 if not isinstance(x0, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x0)) if not isinstance(x1, ptptime.ptptime): assert False, "Incorrect Instance type: '{0}'".format(str(x1)) if not isinstance(x2, ptptime.timedelta): assert False, "Incorrect Instance type: '{0}'".format(str(x2)) d = {'year': 1970, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} checkAttributes(x1, d) d = {'days': 397, 'seconds': 3662, 'microseconds': 0, 'nanoseconds': 1} checkAttributes(x2, d)
def testPTPSubtraction(self): d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(days=1) d['day'] = 11 checkAttributes(tn, d) if not str(tn) == "1972-11-11 16:24:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(hours=1) d['hour'] = 15 checkAttributes(tn, d) if not str(tn) == "1972-11-12 15:24:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(minutes=1) d['minute'] = 23 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:23:34.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(seconds=1) d['second'] = 33 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:33.123456:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(microseconds=1) d['microsecond'] = 123455 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123455:000": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 54, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 53 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123456:053": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 999 d['microsecond'] = 123455 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:34.123455:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 999 d['microsecond'] = 999999 d['second'] = 33 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:24:33.999999:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 999 d['microsecond'] = 999999 d['second'] = 59 d['minute'] = 23 checkAttributes(tn, d) if not str(tn) == "1972-11-12 16:23:59.999999:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 999 d['microsecond'] = 999999 d['second'] = 59 d['minute'] = 59 d['hour'] = 15 checkAttributes(tn, d) if not str(tn) == "1972-11-12 15:59:59.999999:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 999 d['microsecond'] = 999999 d['second'] = 59 d['minute'] = 59 d['hour'] = 23 d['day'] = 11 checkAttributes(tn, d) if not str(tn) == "1972-11-11 23:59:59.999999:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 11 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 999 d['microsecond'] = 999999 d['second'] = 59 d['minute'] = 59 d['hour'] = 23 d['day'] = 31 d['month'] = 10 checkAttributes(tn, d) if not str(tn) == "1972-10-31 23:59:59.999999:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 999 d['microsecond'] = 999999 d['second'] = 59 d['minute'] = 59 d['hour'] = 23 d['day'] = 31 d['month'] = 12 d['year'] = 1971 checkAttributes(tn, d) if not str(tn) == "1971-12-31 23:59:59.999999:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1970, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1) d['nanosecond'] = 999 d['microsecond'] = 999999 d['second'] = 59 d['minute'] = 59 d['hour'] = 23 d['day'] = 31 d['month'] = 12 d['year'] = 1969 checkAttributes(tn, d) if not str(tn) == "1969-12-31 23:59:59.999999:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1001) d['nanosecond'] = 999 d['microsecond'] = 999998 d['second'] = 59 d['minute'] = 59 d['hour'] = 23 d['day'] = 31 d['month'] = 12 d['year'] = 1971 checkAttributes(tn, d) if not str(tn) == "1971-12-31 23:59:59.999998:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn)) d = {'year': 1972, 'month': 1 , 'day': 1, 'hour': 0, 'minute': 0, 'second': 0, 'microsecond': 0, 'nanosecond': 501, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond'],d['nanosecond']) checkAttributes(t, d) tn = t - ptptime.timedelta(nanoseconds=1002) d['nanosecond'] = 499 d['microsecond'] = 999999 d['second'] = 59 d['minute'] = 59 d['hour'] = 23 d['day'] = 31 d['month'] = 12 d['year'] = 1971 checkAttributes(tn, d) if not str(tn) == "1971-12-31 23:59:59.999999:499": assert False, "Incorrect Time Formatting: '{0}'".format(str(tn))
def testPTPError(self): d = {'year': 1972, 'month': 11 , 'day': 12, 'hour': 16, 'minute': 24, 'second': 34, 'microsecond': 123456, 'nanosecond': 0, 'leapyear': False} t = ptptime.ptptime(d['year'],d['month'],d['day'],d['hour'],d['minute'],d['second'],d['microsecond']) checkAttributes(t, d) d['nanosecond'] = 1 t = t.replace(nanosecond=1) checkAttributes(t, d) d['microsecond'] = 1 t = t.replace(microsecond=1) checkAttributes(t, d) d['second'] = 1 t = t.replace(second=1) checkAttributes(t, d) d['minute'] = 1 t = t.replace(minute=1) checkAttributes(t, d) d['hour'] = 1 t = t.replace(hour=1) checkAttributes(t, d) d['day'] = 1 t = t.replace(day=1) checkAttributes(t, d) d['month'] = 1 t = t.replace(month=1) checkAttributes(t, d) d['year'] = 1970 t = t.replace(year=1970) checkAttributes(t, d) self.assertRaises(NameError, t.replace, tree=1) self.assertRaises(NameError, t.replace, nanoseconds=1) self.assertRaises(ValueError, t.replace, microsecond=10000000) self.assertRaises(ValueError, t.replace, second=61) self.assertRaises(ValueError, t.replace, minute=61) self.assertRaises(ValueError, t.replace, hour=24) self.assertRaises(ValueError, t.replace, day=32) self.assertRaises(ValueError, t.replace, month=13) self.assertRaises(TypeError, t.__sub__, 1) self.assertRaises(TypeError, t.__add__, 1) self.assertRaises(TypeError, t.__add__, t) self.assertRaises(TypeError, t.__add__, datetime.datetime.now()) t = t.replace(nanosecond=999) self.assertRaises(ValueError, t.replace, nanosecond=1000) self.assertRaises(ValueError, t.replace, nanosecond=1001)
def testNanoTimeDeltaInit(self): d = ('days', 'seconds', 'microseconds', 'nanoseconds','max', 'min','total_seconds') t = ptptime.timedelta() hasAttributes(t, d) t = ptptime.timedelta(days=1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['days'] = 1 checkAttributes(t, d) if not str(t) == "1 day, 0:00:00": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(hours=1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['seconds'] = 3600 checkAttributes(t, d) if not str(t) == "1:00:00": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(minutes=1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['seconds'] = 60 checkAttributes(t, d) if not str(t) == "0:01:00": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(seconds=1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['seconds'] = 1 checkAttributes(t, d) if not str(t) == "0:00:01": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(microseconds=1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['microseconds'] = 1 checkAttributes(t, d) if not str(t) == "0:00:00.000001": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(nanoseconds=1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['nanoseconds'] = 1 checkAttributes(t, d) t = ptptime.timedelta(nanoseconds=1001) d = {'days': 0, 'seconds': 0, 'microseconds': 1, 'nanoseconds': 0,} d['nanoseconds'] = 1 checkAttributes(t, d) if not str(t) == "0:00:00.000001:001": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(days=1, hours=1, minutes=1, seconds=1, microseconds=1, nanoseconds=1) d = {'days': 1, 'seconds': 3661, 'microseconds': 1, 'nanoseconds': 1,} checkAttributes(t, d) if not str(t) == "1 day, 1:01:01.000001:001": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(days=-1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['days'] = -1 checkAttributes(t, d) if not str(t) == "-1 day, 0:00:00": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(hours=-1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['days'] = -1 d['seconds'] = 82800 checkAttributes(t, d) if not str(t) == "-1 day, 23:00:00": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(minutes=-1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['days'] = -1 d['seconds'] = 86340 checkAttributes(t, d) if not str(t) == "-1 day, 23:59:00": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(seconds=-1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['days'] = -1 d['seconds'] = 86399 checkAttributes(t, d) if not str(t) == "-1 day, 23:59:59": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(microseconds=-1) d = {'days': 0, 'seconds': 0, 'microseconds': 0, 'nanoseconds': 0,} d['days'] = -1 d['seconds'] = 86399 d['microseconds'] = 999999 checkAttributes(t, d) if not str(t) == "-1 day, 23:59:59.999999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(days=-1, hours=-1) d = {'days': -2, 'seconds': 82800, 'microseconds': 0, 'nanoseconds': 0,} checkAttributes(t, d) if not str(t) == "-2 days, 23:00:00": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(days=-1, hours=-1, minutes=-1) d = {'days': -2, 'seconds': 82740, 'microseconds': 0, 'nanoseconds': 0,} checkAttributes(t, d) if not str(t) == "-2 days, 22:59:00": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(days=-1, hours=-1, minutes=-1, seconds=-1) d = {'days': -2, 'seconds': 82739, 'microseconds': 0, 'nanoseconds': 0,} checkAttributes(t, d) if not str(t) == "-2 days, 22:58:59": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(days=-1, hours=-1, minutes=-1, seconds=-1, microseconds=-1, nanoseconds=1) d = {'days': -2, 'seconds': 82738, 'microseconds': 999999, 'nanoseconds': 1,} checkAttributes(t, d) if not str(t) == "-2 days, 22:58:58.999999:001": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(nanoseconds=-1) d = {'days': -1, 'seconds': 86399, 'microseconds': 999999, 'nanoseconds': 999,} checkAttributes(t, d) if not str(t) == "-1 day, 23:59:59.999999:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(nanoseconds=-1001) d = {'days': -1, 'seconds': 86399, 'microseconds': 999998, 'nanoseconds': 999,} checkAttributes(t, d) if not str(t) == "-1 day, 23:59:59.999998:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(microseconds=-1, nanoseconds=-1) d = {'days': -1, 'seconds': 86399, 'microseconds': 999998, 'nanoseconds': 999,} checkAttributes(t, d) if not str(t) == "-1 day, 23:59:59.999998:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(seconds=-1, microseconds=-1, nanoseconds=-1) d = {'days': -1, 'seconds': 86398, 'microseconds': 999998, 'nanoseconds': 999,} checkAttributes(t, d) if not str(t) == "-1 day, 23:59:58.999998:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(minutes=-1, seconds=-1, microseconds=-1, nanoseconds=-1) d = {'days': -1, 'seconds': 86338, 'microseconds': 999998, 'nanoseconds': 999,} checkAttributes(t, d) if not str(t) == "-1 day, 23:58:58.999998:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = datetime.timedelta(hours=-1, minutes=-1, seconds=-1, microseconds=-1) if not str(t) == "-1 day, 22:58:58.999999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) d = {'days': -1, 'seconds': 82738, 'microseconds': 999999} checkAttributes(t, d) t = ptptime.timedelta(hours=-1, minutes=-1, seconds=-1, microseconds=-1) d = {'days': -1, 'seconds': 82738, 'microseconds': 999999, 'nanoseconds': 0,} checkAttributes(t, d) if not str(t) == "-1 day, 22:58:58.999999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(hours=-1, minutes=-1, seconds=-1, microseconds=-1, nanoseconds=-1) d = {'days': -1, 'seconds': 82738, 'microseconds': 999998, 'nanoseconds': 999,} checkAttributes(t, d) if not str(t) == "-1 day, 22:58:58.999998:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t)) t = ptptime.timedelta(days=-1, hours=-1, minutes=-1, seconds=-1, microseconds=-1, nanoseconds=-1) d = {'days': -2, 'seconds': 82738, 'microseconds': 999998, 'nanoseconds': 999,} checkAttributes(t, d) if not str(t) == "-2 days, 22:58:58.999998:999": assert False, "Incorrect Time Formatting: '{0}'".format(str(t))