#Time programming: d = gregorian.date(2002, date_time.Feb, 1) #an arbitrary date t1 = posix_time.ptime(d, posix_time.hours(5) + posix_time.millisec(100)) #date + time of day offset print 't1: ', to_simple_string(t1) t2 = t1 - posix_time.minutes(4) + posix_time.seconds(2) print 't2: ', to_simple_string(t2) now = posix_time.second_clock.local_time() #use the clock print 'now: ', to_simple_string(now) today = now.date() #Get the date part out of the time print 'today: ', to_simple_string(today) tomorrow = today + gregorian.date_duration(1) print 'tomorrow: ', to_simple_string(tomorrow) #Local time programming: #setup some timezones for creating and adjusting times #first time zone uses the time zone file for regional timezone definitions tz_db = local_time.time_zone_database() tz_db.load_from_file( os.path.join(date_time.__path__[0], "date_time_zonespec.csv")) nyc_tz = tz_db.time_zone_from_region("America/New_York") #This timezone uses a posix time zone string definition to create a time zone phx_tz = local_time.posix_time_zone("MST-07:00:00") #local departure time in phoenix is 11 pm on April 2 2005 #Note that New York changes to daylight savings on Apr 3 at 2 am) phx_departure = local_time.local_date_time(
def test_time(self): td_pi = posix_time.time_duration(date_time.pos_infin) td_ni = posix_time.time_duration(date_time.neg_infin) td_ndt = posix_time.time_duration(date_time.not_a_date_time) dd_pi = gregorian.date_duration(date_time.pos_infin) dd_ni = gregorian.date_duration(date_time.neg_infin) dd_ndt = gregorian.date_duration(date_time.not_a_date_time) d_pi = gregorian.date(date_time.pos_infin) d_ni = gregorian.date(date_time.neg_infin) d_ndt = gregorian.date(date_time.not_a_date_time) td = posix_time.time_duration(1,2,3,4) dd = gregorian.date_duration(1234); d = gregorian.date(2003, date_time.Oct,31) self.failUnless( posix_time.ptime() == posix_time.ptime(date_time.not_a_date_time) ) s = "+infinity" p_sv1 = posix_time.ptime(date_time.pos_infin); self.failUnless( to_simple_string(p_sv1) == s ) result = p_sv1 + dd self.failUnless( to_iso_string(result) == s ) self.failUnless( result.is_special() ) result = p_sv1 - dd self.failUnless( to_iso_string(result) == s) result = p_sv1 - dd_ni self.failUnless( to_iso_string(result) == s) p_sv2 = posix_time.ptime(date_time.neg_infin) s = "-infinity" self.failUnless( to_iso_string(p_sv2) == s) result = p_sv2 - td_pi self.failUnless( to_iso_string(result) == s ) p_sv3 = posix_time.ptime(date_time.not_a_date_time) self.failUnless( p_sv3.is_special() ) s = "not-a-date-time"; self.failUnless( to_iso_string(p_sv3) == s) result = p_sv3 + td self.failUnless( to_iso_string(result) == s) result = p_sv3 - td self.failUnless( to_iso_string(result) == s) result = p_sv2 + td_pi self.failUnless( to_iso_string(result) == s) result = p_sv1 + dd_ni self.failUnless( to_iso_string(result) == s) result = p_sv1 + dd_ndt self.failUnless( to_iso_string(result) == s) p_sv1 = posix_time.ptime(d_pi, td) s = "+infinity" self.failUnless( to_simple_string(p_sv1) == s) p_sv2 = posix_time.ptime(d_ni, td) s = "-infinity"; self.failUnless( to_iso_string(p_sv2) == s) p_sv3 = posix_time.ptime(d_ndt, td) s = "not-a-date-time"; self.failUnless( to_iso_string(p_sv3) == s) p_sv1 = posix_time.ptime(d_ndt, td) s = "not-a-date-time" self.failUnless( to_simple_string(p_sv1) == s) p_sv2 = posix_time.ptime(d, td_ndt) self.failUnless( to_iso_string(p_sv2) == s) p_sv3 = posix_time.ptime(d_pi, td_ni) self.failUnless( to_iso_string(p_sv3) == s) p_sv1 = posix_time.ptime(d, td_pi) pt = posix_time.ptime(d,td) s = "+infinity" self.failUnless( to_simple_string(p_sv1) == s) self.failUnless( to_simple_string(p_sv1.date()) == s) p_sv2 = posix_time.ptime(d, td_ni) s = "-infinity" self.failUnless( to_iso_string(p_sv2) == s) self.failUnless( to_simple_string(p_sv2.time_of_day()) == s) p_sv3 = posix_time.ptime(d, td_ndt) s = "not-a-date-time" self.failUnless( to_iso_string(p_sv3) == s) self.failUnless( to_simple_string(p_sv3.date()) == s) self.failUnless( to_simple_string(p_sv3.time_of_day()) == s) self.failUnless( p_sv2 < p_sv1) self.failUnless( p_sv2 < pt) self.failUnless( pt < p_sv1) self.failUnless( p_sv2 <= p_sv2) self.failUnless( p_sv2 <= pt) self.failUnless( p_sv1 >= pt) self.failUnless( p_sv1 != p_sv2) self.failUnless( p_sv3 != p_sv2) self.failUnless( pt != p_sv1) self.failUnless( p_sv1.is_infinity() and p_sv1.is_pos_infinity()) self.failUnless( p_sv2.is_infinity() and p_sv2.is_neg_infinity()) self.failUnless( not p_sv3.is_infinity() and p_sv3.is_not_a_date_time()) self.failUnless( p_sv1 + dd == p_sv1) self.failUnless( pt - dd_pi == p_sv2) self.failUnless( pt - dd_ndt == p_sv3) self.failUnless( p_sv2 + td == p_sv2) self.failUnless( pt - td_ni == p_sv1) self.failUnless( pt + td_ndt == p_sv3) self.failUnless( pt - p_sv1 == td_ni) self.failUnless( pt - p_sv2 == td_pi) self.failUnless( pt - p_sv3 == td_ndt) self.failUnless( p_sv2 - p_sv2 == td_ndt) d = gregorian.date(2001, date_time.Dec,1) td = posix_time.time_duration(5,4,3) t1 = posix_time.ptime(d, td) self.failUnless( t1.date() == d) self.failUnless( t1.time_of_day() == td) self.failUnless( posix_time.ptime( gregorian.date(2005,10,30), posix_time.hours(25)) == posix_time.ptime(gregorian.date(2005,10,31), posix_time.hours(1))) t2 = posix_time.ptime(d, td) t3 = posix_time.ptime(d, td) self.failUnless( t3.date() == d) self.failUnless( t3.time_of_day() == td) self.failUnless( t1 == t3) d2 = gregorian.date(2001,date_time.Jan,1) t4 = posix_time.ptime(d2, td) self.failUnless( not (t1 == t4)) td1 = posix_time.time_duration(5,4,0) t5 = posix_time.ptime(d, td1) self.failUnless( not (t1 == t5)) self.failUnless( t1 != t5); self.failUnless( not (t1 < t1) ) self.failUnless( t4 < t1) self.failUnless( t5 < t1) self.failUnless( t1 <= t1) self.failUnless( t1 >= t1) twodays = gregorian.date_duration(2) t6 = t1 + twodays d3 = gregorian.date(2001,date_time.Dec,3) self.failUnless( t6 == posix_time.ptime(d3,td) ) t7 = t1 - twodays self.failUnless( t7 == posix_time.ptime(gregorian.date(2001,date_time.Nov,29),td) ) t6b = posix_time.ptime( gregorian.date(2003, date_time.Oct,31) , posix_time.time_duration(10,0,0,0)) t6b += gregorian.date_duration(55) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003,date_time.Dec,25) , posix_time.time_duration(10,0,0,0))) t6b += posix_time.hours(6) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003,date_time.Dec,25) , posix_time.time_duration(16,0,0,0))) t6b -= gregorian.date_duration(55) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003,date_time.Oct,31) , posix_time.time_duration(16,0,0,0))) t6b -= posix_time.hours(6) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003,date_time.Oct,31) , posix_time.time_duration(10,0,0,0))); t6b += posix_time.hours(25); self.failUnless( t6b == posix_time.ptime(gregorian.date(2003,date_time.Nov,1), posix_time.time_duration(11,0,0,0))); t6b -= posix_time.hours(49); self.failUnless( t6b == posix_time.ptime(gregorian.date(2003,date_time.Oct,30) , posix_time.time_duration(10,0,0,0))); td2 = posix_time.time_duration(1,2,3) t8 = posix_time.ptime(gregorian.date(2001,date_time.Dec,1)) t9 = t8 + td2 t10 = posix_time.ptime(gregorian.date(2001,date_time.Dec,1) ,posix_time.time_duration(1,2,3)) self.failUnless( t9 == t10) t9 = posix_time.ptime(gregorian.date(2001,date_time.Dec,1) , posix_time.time_duration(12,0,0)); td3 = posix_time.time_duration(-4,0,0) self.failUnless( t9 + td3 == posix_time.ptime(gregorian.date(2001,date_time.Dec,1) , posix_time.time_duration(8,0,0)) ) td3 = posix_time.time_duration(24,0,0) self.failUnless( t8+td3 == posix_time.ptime(gregorian.date(2001,date_time.Dec,2) ) ) td4 = posix_time.time_duration(24,0,1) self.failUnless( t8+td4 == posix_time.ptime(gregorian.date(2001,date_time.Dec,2) , posix_time.time_duration(0,0,1))); td5 = posix_time.time_duration(168,0,1) self.failUnless( t8+td5 == posix_time.ptime(gregorian.date(2001,date_time.Dec,8) , posix_time.time_duration(0,0,1))) t11 = posix_time.ptime(gregorian.date(2001,date_time.Dec,1) , posix_time.time_duration(12,0,0)) td6 = posix_time.time_duration(12,0,1) t12 = t11-td6 self.failUnless( t12 == posix_time.ptime(gregorian.date(2001,date_time.Nov,30) , posix_time.time_duration(23,59,59))) self.failUnless( t11-posix_time.time_duration(13,0,0) == posix_time.ptime(gregorian.date(2001,date_time.Nov,30) , posix_time.time_duration(23,0,0))) self.failUnless( t11-posix_time.time_duration(-13,0,0) == posix_time.ptime(gregorian.date(2001,date_time.Dec,2) , posix_time.time_duration(1,0,0))) t13 = posix_time.ptime(d, posix_time.hours(3)) t14 = posix_time.ptime(d, posix_time.hours(4)) t14a = posix_time.ptime(d+gregorian.date_duration(1), posix_time.hours(4)) self.failUnless( t14-t13 == posix_time.hours(1)) self.failUnless( t13 - t14 == posix_time.hours(-1)) self.failUnless( t14a-t14 == posix_time.hours(24)) t15 = posix_time.ptime(d, posix_time.time_duration(0,0,0,1)) t16 = posix_time.ptime(d, posix_time.time_duration(0,0,0,2)) self.failUnless( t15 + posix_time.time_duration.unit() == t16) self.failUnless( t16 - posix_time.time_duration.unit() == t15) self.failUnless( posix_time.ptime(date_time.min_date_time) == posix_time.ptime(gregorian.date(1400,1,1) , posix_time.time_duration(0,0,0,0)) ) self.failUnless( posix_time.ptime(date_time.max_date_time) == posix_time.ptime(gregorian.date(9999,12,31) , posix_time.hours(24)- posix_time.time_duration.unit()))
# Time programming: d = gregorian.date(2002, date_time.Feb, 1) # an arbitrary date t1 = posix_time.ptime(d, posix_time.hours(5) + posix_time.millisec(100)) # date + time of day offset print "t1: ", to_simple_string(t1) t2 = t1 - posix_time.minutes(4) + posix_time.seconds(2) print "t2: ", to_simple_string(t2) now = posix_time.second_clock.local_time() # use the clock print "now: ", to_simple_string(now) today = now.date() # Get the date part out of the time print "today: ", to_simple_string(today) tomorrow = today + gregorian.date_duration(1) print "tomorrow: ", to_simple_string(tomorrow) # Local time programming: # setup some timezones for creating and adjusting times # first time zone uses the time zone file for regional timezone definitions tz_db = local_time.time_zone_database() tz_db.load_from_file(os.path.join(date_time.__path__[0], "date_time_zonespec.csv")) nyc_tz = tz_db.time_zone_from_region("America/New_York") # This timezone uses a posix time zone string definition to create a time zone phx_tz = local_time.posix_time_zone("MST-07:00:00") # local departure time in phoenix is 11 pm on April 2 2005 # Note that New York changes to daylight savings on Apr 3 at 2 am) phx_departure = local_time.local_date_time( gregorian.date(2005, date_time.Apr, 2),
def test_date(self): self.failUnless( gregorian.date() == gregorian.date(date_time.not_a_date_time)) d1 = gregorian.date(1900, 1, 1) d2 = gregorian.date(2000, 1, 1) d3 = gregorian.date(1900, 1, 1) d4 = gregorian.date(2000, 12, 31) d4a = gregorian.date(2000, date_time.Dec, 31) self.failUnless(d4 == d4a) self.failUnless(d1.day().as_number() == 1) self.failUnless(d1.month().as_number() == 1) self.failUnless(d1.year().as_number() == 1900) self.failUnless(d4a.month().as_number() == 12) self.failUnless(d1 < d2) self.failUnless(not (d1 < d1)) self.failUnless(d1 <= d1) self.failUnless(d2 > d1) self.failUnless(not (d1 > d1)) self.failUnless(d1 >= d1) self.failUnless(d2 != d1) self.failUnless(d1 == d3) ymd = d1.year_month_day() self.failUnless(ymd.year.as_number() == 1900) self.failUnless(ymd.month.as_number() == 1) self.failUnless(ymd.day.as_number() == 1) answers = [ gregorian.date(1900, date_time.Jan, 1), gregorian.date(1900, date_time.Jan, 4), gregorian.date(1900, date_time.Jan, 7), gregorian.date(1900, date_time.Jan, 10), gregorian.date(1900, date_time.Jan, 13) ] off = gregorian.date_duration(3) d5 = gregorian.date(1900, 1, 1) for i in range(5): self.failUnless(d5 == answers[i]) d5 = d5 + off answers1 = [ gregorian.date(2000, 2, 26), gregorian.date(2000, 2, 28), gregorian.date(2000, date_time.Mar, 1) ] d8 = gregorian.date(2000, date_time.Feb, 26) for i in range(3): self.failUnless(d8 == answers1[i]) d8 += gregorian.days(2) d6 = gregorian.date(2000, 2, 28) d7 = gregorian.date(2000, 3, 1) twoDays = gregorian.date_duration(2) negtwoDays = gregorian.date_duration(-2) zeroDays = gregorian.date_duration(0) self.failUnless(twoDays == d7 - d6) self.failUnless(negtwoDays == d6 - d7) self.failUnless(zeroDays == d6 - d6) self.failUnless(d6 + twoDays == d7) self.failUnless(d7 - twoDays == d6) self.failUnless( gregorian.date(1999, 1, 1) + gregorian.date_duration(365) == gregorian.date(2000, 1, 1)) self.failUnless( gregorian.date(1999, 1, 1) + zeroDays == gregorian.date(1999, 1, 1)) d = gregorian.date(2003, date_time.Oct, 31) dd = gregorian.date_duration(55) d += dd self.failUnless(d == gregorian.date(2003, date_time.Dec, 25)) d -= dd self.failUnless(d == gregorian.date(2003, date_time.Oct, 31)) d = gregorian.date(2003, date_time.Oct, 31) dd1 = gregorian.date_duration(date_time.pos_infin) dd2 = gregorian.date_duration(date_time.neg_infin) dd3 = gregorian.date_duration(date_time.not_a_date_time) self.failUnless(d + dd1 == gregorian.date(date_time.pos_infin)) self.failUnless(d + dd2 == gregorian.date(date_time.neg_infin)) self.failUnless(d + dd3 == gregorian.date(date_time.not_a_date_time)) self.failUnless(d - dd1 == gregorian.date(date_time.neg_infin)) self.failUnless(d - dd2 == gregorian.date(date_time.pos_infin)) self.failUnless(d - dd3 == gregorian.date(date_time.not_a_date_time)) self.failUnless( gregorian.date(date_time.pos_infin) + dd1 == gregorian.date(date_time.pos_infin)) self.failUnless( gregorian.date(date_time.pos_infin) - dd1 == gregorian.date(date_time.not_a_date_time)) self.failUnless( gregorian.date(date_time.neg_infin) + dd1 == gregorian.date(date_time.not_a_date_time)) self.failUnless( gregorian.date(date_time.neg_infin) - dd1 == gregorian.date(date_time.neg_infin)) self.failUnlessRaises(Exception, lambda: gregorian.date(2000, 1, 32)) self.failUnlessRaises(Exception, lambda: gregorian.date(2000, 1, 0)) self.failUnlessRaises(Exception, lambda: gregorian.date(2000, 2, 31)) d15 = gregorian.date(1400, 1, 1) self.failUnless(d15.julian_day() == 2232400) self.failUnless(d15.modjulian_day() == -167601) d16 = gregorian.date(2004, 2, 29) self.failUnless(d16.julian_day() == 2453065) self.failUnless(d16.modjulian_day() == 53064) d31 = gregorian.date(2000, date_time.Jun, 1) self.failUnless(d31.week_number() == 22) d38 = gregorian.date(2001, 1, 1) self.failUnless(d38.day_of_year().as_number() == 1)
def test_period(self): d1 = gregorian.date(2000, date_time.Jan, 1) d2 = gregorian.date(2000, date_time.Jan, 4) p1 = gregorian.date_period(d1, d2) p2 = gregorian.date_period(d1, gregorian.date_duration(3)) self.failUnless(p1 == p2) self.failUnless(p1.begin() == d1) self.failUnless(p1.last() == d2 - gregorian.date_duration(1)) self.failUnless(p1.end() == d2) self.failUnless(p2.length() == gregorian.date_duration(3)) self.failUnless(p1.contains(d1)) self.failUnless(not p1.contains(d2)) p3 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 4), gregorian.date(2000, date_time.Feb, 1)) self.failUnless(not (p1 == p3)) self.failUnless(p1 < p3) self.failUnless(p3 > p1) self.failUnless(p3 != p1) self.failUnless(p1.intersects(p1)) self.failUnless(not p1.intersects(p3)) self.failUnless(not p3.intersects(p1)) p4 = gregorian.date_period(gregorian.date(1999, date_time.Dec, 1), d2) self.failUnless(p1.intersects(p4)) self.failUnless(p4.intersects(p1)) p5 = gregorian.date_period(gregorian.date(1999, date_time.Dec, 1), gregorian.date(2000, date_time.Dec, 31)) self.failUnless(p1.intersects(p5)) self.failUnless(p5.intersects(p1)) p6 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 1), gregorian.date(2000, date_time.Dec, 31)) self.failUnless(p5.contains(p6)) self.failUnless(p6.contains(p6)) self.failUnless(not p6.contains(p5)) fourDays = gregorian.date_duration(4) p1.shift(fourDays) shifted = gregorian.date_period(gregorian.date(2000, date_time.Jan, 5), gregorian.date(2000, date_time.Jan, 8)) self.failUnless(p1 == shifted) i1 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 5), gregorian.date(2000, date_time.Jan, 10)) i2 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 1), gregorian.date(2000, date_time.Jan, 7)) r1 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 5), gregorian.date(2000, date_time.Jan, 7)) self.failUnless(i1.intersection(i2) == r1) self.failUnless(i2.intersection(i1) == r1) i3 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 1), gregorian.date(2000, date_time.Jan, 15)) self.failUnless(i1.intersection(i3) == i1) self.failUnless(i3.intersection(i1) == i1) i4 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 7), gregorian.date(2000, date_time.Jan, 10)) i5 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 6), gregorian.date(2000, date_time.Jan, 9)) self.failUnless(i1.intersection(i5) == i5) self.failUnless(i5.intersection(i1) == i5) self.failUnless(i2.intersection(i4).is_null()) r3 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 1), gregorian.date(2000, date_time.Jan, 10)) self.failUnless(i1.merge(i2) == r3) self.failUnless(i2.merge(i4).is_null()) r4 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 5), gregorian.date(2000, date_time.Jan, 10)) self.failUnless(i1.merge(i5) == r4) self.failUnless(i1.span(i2) == r3) self.failUnless(i2.span(i4) == r3) self.failUnless(i4.span(i2) == r3) self.failUnless(i3.span(i2) == i3) i6 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 1), gregorian.date(2000, date_time.Jan, 2)) self.failUnless(i6.span(i4) == r3) self.failUnless(i4.span(i6) == r3) bf_start = gregorian.date(2000, date_time.Jan, 5) bf_end = gregorian.date(2000, date_time.Jan, 10) bf_before = gregorian.date(2000, date_time.Jan, 4) bf_after = gregorian.date(2000, date_time.Jan, 11) bf_during = gregorian.date(2000, date_time.Jan, 7) bfp1 = gregorian.date_period(bf_start, bf_end) self.failUnless(not bfp1.is_before(bf_start)) self.failUnless(bfp1.is_before(bf_end)) self.failUnless(not bfp1.is_before(bfp1.last())) self.failUnless(not bfp1.is_before(bf_before)) self.failUnless(not bfp1.is_before(bf_during)) self.failUnless(bfp1.is_before(bf_after)) self.failUnless(not bfp1.is_after(bf_start)) self.failUnless(not bfp1.is_after(bf_end)) self.failUnless(not bfp1.is_after(bfp1.last())) self.failUnless(bfp1.is_after(bf_before)) self.failUnless(not bfp1.is_after(bf_during)) self.failUnless(not bfp1.is_after(bf_after)) adj1 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 5), gregorian.date(2000, date_time.Jan, 10)) adj2 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 1), gregorian.date(2000, date_time.Jan, 5)) adj3 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 7), gregorian.date(2000, date_time.Jan, 12)) adj4 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 12), gregorian.date(2000, date_time.Jan, 15)) adj5 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 1), gregorian.date(2000, date_time.Jan, 3)) adj6 = gregorian.date_period(gregorian.date(2000, date_time.Jan, 7), gregorian.date(2000, date_time.Jan, 9)) self.failUnless(adj1.is_adjacent(adj2)) self.failUnless(adj2.is_adjacent(adj1)) self.failUnless(not adj1.is_adjacent(adj3)) self.failUnless(not adj3.is_adjacent(adj1)) self.failUnless(not adj1.is_adjacent(adj4)) self.failUnless(not adj4.is_adjacent(adj1)) self.failUnless(not adj1.is_adjacent(adj5)) self.failUnless(not adj5.is_adjacent(adj1)) self.failUnless(not adj1.is_adjacent(adj6)) self.failUnless(not adj6.is_adjacent(adj1))
def test_date_duration(self): threeDays = gregorian.date_duration(3) twoDays = gregorian.date_duration(2) self.failUnless(threeDays == threeDays) self.failUnless(threeDays == gregorian.date_duration(3)) self.failUnless(threeDays != twoDays) self.failUnless(twoDays < threeDays) self.failUnless(not (threeDays < twoDays)) self.failUnless(not (threeDays < threeDays)) self.failUnless(not (threeDays > threeDays)) self.failUnless(threeDays >= threeDays) self.failUnless(not (twoDays >= threeDays)) self.failUnless(twoDays + threeDays == gregorian.date_duration(5)) fiveDays = gregorian.date_duration(3) fiveDays += twoDays self.failUnless(fiveDays == gregorian.date_duration(5)) derivedOneDay = threeDays - twoDays self.failUnless(twoDays - threeDays == gregorian.date_duration(-1)) oneDay = gregorian.date_duration(1) self.failUnless(oneDay == derivedOneDay) fiveDaysDerived = gregorian.date_duration(10) fiveDaysDerived -= fiveDays self.failUnless(fiveDaysDerived == fiveDays) oneDay = twoDays / 2 self.failUnless(oneDay.days() == 1) hundred = gregorian.date_duration(100) hundred /= -10 self.failUnless(hundred.days() == -10 and hundred.is_negative()) self.failUnless( gregorian.date_duration( -gregorian.date_duration(123).days()).days() == -123) pos_dur = gregorian.date_duration(123) neg_dur = -pos_dur self.failUnless(neg_dur.days() == -123) pi_dur = gregorian.date_duration(date_time.pos_infin) ni_dur = gregorian.date_duration(date_time.neg_infin) nd_dur = gregorian.date_duration(date_time.not_a_date_time) self.failUnless(pi_dur + ni_dur == nd_dur) self.failUnless(ni_dur / 3 == ni_dur) self.failUnless(pi_dur + hundred == pi_dur) self.failUnless(-pi_dur == ni_dur)
def test_time(self): td_pi = posix_time.time_duration(date_time.pos_infin) td_ni = posix_time.time_duration(date_time.neg_infin) td_ndt = posix_time.time_duration(date_time.not_a_date_time) dd_pi = gregorian.date_duration(date_time.pos_infin) dd_ni = gregorian.date_duration(date_time.neg_infin) dd_ndt = gregorian.date_duration(date_time.not_a_date_time) d_pi = gregorian.date(date_time.pos_infin) d_ni = gregorian.date(date_time.neg_infin) d_ndt = gregorian.date(date_time.not_a_date_time) td = posix_time.time_duration(1, 2, 3, 4) dd = gregorian.date_duration(1234) d = gregorian.date(2003, date_time.Oct, 31) self.failUnless( posix_time.ptime() == posix_time.ptime(date_time.not_a_date_time)) s = "+infinity" p_sv1 = posix_time.ptime(date_time.pos_infin) self.failUnless(to_simple_string(p_sv1) == s) result = p_sv1 + dd self.failUnless(to_iso_string(result) == s) self.failUnless(result.is_special()) result = p_sv1 - dd self.failUnless(to_iso_string(result) == s) result = p_sv1 - dd_ni self.failUnless(to_iso_string(result) == s) p_sv2 = posix_time.ptime(date_time.neg_infin) s = "-infinity" self.failUnless(to_iso_string(p_sv2) == s) result = p_sv2 - td_pi self.failUnless(to_iso_string(result) == s) p_sv3 = posix_time.ptime(date_time.not_a_date_time) self.failUnless(p_sv3.is_special()) s = "not-a-date-time" self.failUnless(to_iso_string(p_sv3) == s) result = p_sv3 + td self.failUnless(to_iso_string(result) == s) result = p_sv3 - td self.failUnless(to_iso_string(result) == s) result = p_sv2 + td_pi self.failUnless(to_iso_string(result) == s) result = p_sv1 + dd_ni self.failUnless(to_iso_string(result) == s) result = p_sv1 + dd_ndt self.failUnless(to_iso_string(result) == s) p_sv1 = posix_time.ptime(d_pi, td) s = "+infinity" self.failUnless(to_simple_string(p_sv1) == s) p_sv2 = posix_time.ptime(d_ni, td) s = "-infinity" self.failUnless(to_iso_string(p_sv2) == s) p_sv3 = posix_time.ptime(d_ndt, td) s = "not-a-date-time" self.failUnless(to_iso_string(p_sv3) == s) p_sv1 = posix_time.ptime(d_ndt, td) s = "not-a-date-time" self.failUnless(to_simple_string(p_sv1) == s) p_sv2 = posix_time.ptime(d, td_ndt) self.failUnless(to_iso_string(p_sv2) == s) p_sv3 = posix_time.ptime(d_pi, td_ni) self.failUnless(to_iso_string(p_sv3) == s) p_sv1 = posix_time.ptime(d, td_pi) pt = posix_time.ptime(d, td) s = "+infinity" self.failUnless(to_simple_string(p_sv1) == s) self.failUnless(to_simple_string(p_sv1.date()) == s) p_sv2 = posix_time.ptime(d, td_ni) s = "-infinity" self.failUnless(to_iso_string(p_sv2) == s) self.failUnless(to_simple_string(p_sv2.time_of_day()) == s) p_sv3 = posix_time.ptime(d, td_ndt) s = "not-a-date-time" self.failUnless(to_iso_string(p_sv3) == s) self.failUnless(to_simple_string(p_sv3.date()) == s) self.failUnless(to_simple_string(p_sv3.time_of_day()) == s) self.failUnless(p_sv2 < p_sv1) self.failUnless(p_sv2 < pt) self.failUnless(pt < p_sv1) self.failUnless(p_sv2 <= p_sv2) self.failUnless(p_sv2 <= pt) self.failUnless(p_sv1 >= pt) self.failUnless(p_sv1 != p_sv2) self.failUnless(p_sv3 != p_sv2) self.failUnless(pt != p_sv1) self.failUnless(p_sv1.is_infinity() and p_sv1.is_pos_infinity()) self.failUnless(p_sv2.is_infinity() and p_sv2.is_neg_infinity()) self.failUnless(not p_sv3.is_infinity() and p_sv3.is_not_a_date_time()) self.failUnless(p_sv1 + dd == p_sv1) self.failUnless(pt - dd_pi == p_sv2) self.failUnless(pt - dd_ndt == p_sv3) self.failUnless(p_sv2 + td == p_sv2) self.failUnless(pt - td_ni == p_sv1) self.failUnless(pt + td_ndt == p_sv3) self.failUnless(pt - p_sv1 == td_ni) self.failUnless(pt - p_sv2 == td_pi) self.failUnless(pt - p_sv3 == td_ndt) self.failUnless(p_sv2 - p_sv2 == td_ndt) d = gregorian.date(2001, date_time.Dec, 1) td = posix_time.time_duration(5, 4, 3) t1 = posix_time.ptime(d, td) self.failUnless(t1.date() == d) self.failUnless(t1.time_of_day() == td) self.failUnless( posix_time.ptime(gregorian.date(2005, 10, 30), posix_time.hours( 25)) == posix_time.ptime(gregorian.date(2005, 10, 31), posix_time.hours(1))) t2 = posix_time.ptime(d, td) t3 = posix_time.ptime(d, td) self.failUnless(t3.date() == d) self.failUnless(t3.time_of_day() == td) self.failUnless(t1 == t3) d2 = gregorian.date(2001, date_time.Jan, 1) t4 = posix_time.ptime(d2, td) self.failUnless(not (t1 == t4)) td1 = posix_time.time_duration(5, 4, 0) t5 = posix_time.ptime(d, td1) self.failUnless(not (t1 == t5)) self.failUnless(t1 != t5) self.failUnless(not (t1 < t1)) self.failUnless(t4 < t1) self.failUnless(t5 < t1) self.failUnless(t1 <= t1) self.failUnless(t1 >= t1) twodays = gregorian.date_duration(2) t6 = t1 + twodays d3 = gregorian.date(2001, date_time.Dec, 3) self.failUnless(t6 == posix_time.ptime(d3, td)) t7 = t1 - twodays self.failUnless(t7 == posix_time.ptime( gregorian.date(2001, date_time.Nov, 29), td)) t6b = posix_time.ptime(gregorian.date(2003, date_time.Oct, 31), posix_time.time_duration(10, 0, 0, 0)) t6b += gregorian.date_duration(55) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003, date_time.Dec, 25), posix_time.time_duration(10, 0, 0, 0))) t6b += posix_time.hours(6) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003, date_time.Dec, 25), posix_time.time_duration(16, 0, 0, 0))) t6b -= gregorian.date_duration(55) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003, date_time.Oct, 31), posix_time.time_duration(16, 0, 0, 0))) t6b -= posix_time.hours(6) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003, date_time.Oct, 31), posix_time.time_duration(10, 0, 0, 0))) t6b += posix_time.hours(25) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003, date_time.Nov, 1), posix_time.time_duration(11, 0, 0, 0))) t6b -= posix_time.hours(49) self.failUnless( t6b == posix_time.ptime(gregorian.date(2003, date_time.Oct, 30), posix_time.time_duration(10, 0, 0, 0))) td2 = posix_time.time_duration(1, 2, 3) t8 = posix_time.ptime(gregorian.date(2001, date_time.Dec, 1)) t9 = t8 + td2 t10 = posix_time.ptime(gregorian.date(2001, date_time.Dec, 1), posix_time.time_duration(1, 2, 3)) self.failUnless(t9 == t10) t9 = posix_time.ptime(gregorian.date(2001, date_time.Dec, 1), posix_time.time_duration(12, 0, 0)) td3 = posix_time.time_duration(-4, 0, 0) self.failUnless( t9 + td3 == posix_time.ptime(gregorian.date(2001, date_time.Dec, 1), posix_time.time_duration(8, 0, 0))) td3 = posix_time.time_duration(24, 0, 0) self.failUnless( t8 + td3 == posix_time.ptime(gregorian.date(2001, date_time.Dec, 2))) td4 = posix_time.time_duration(24, 0, 1) self.failUnless( t8 + td4 == posix_time.ptime(gregorian.date(2001, date_time.Dec, 2), posix_time.time_duration(0, 0, 1))) td5 = posix_time.time_duration(168, 0, 1) self.failUnless( t8 + td5 == posix_time.ptime(gregorian.date(2001, date_time.Dec, 8), posix_time.time_duration(0, 0, 1))) t11 = posix_time.ptime(gregorian.date(2001, date_time.Dec, 1), posix_time.time_duration(12, 0, 0)) td6 = posix_time.time_duration(12, 0, 1) t12 = t11 - td6 self.failUnless( t12 == posix_time.ptime(gregorian.date(2001, date_time.Nov, 30), posix_time.time_duration(23, 59, 59))) self.failUnless(t11 - posix_time.time_duration(13, 0, 0) == posix_time.ptime( gregorian.date(2001, date_time.Nov, 30), posix_time.time_duration(23, 0, 0))) self.failUnless( t11 - posix_time.time_duration(-13, 0, 0) == posix_time.ptime( gregorian.date(2001, date_time.Dec, 2), posix_time.time_duration(1, 0, 0))) t13 = posix_time.ptime(d, posix_time.hours(3)) t14 = posix_time.ptime(d, posix_time.hours(4)) t14a = posix_time.ptime(d + gregorian.date_duration(1), posix_time.hours(4)) self.failUnless(t14 - t13 == posix_time.hours(1)) self.failUnless(t13 - t14 == posix_time.hours(-1)) self.failUnless(t14a - t14 == posix_time.hours(24)) t15 = posix_time.ptime(d, posix_time.time_duration(0, 0, 0, 1)) t16 = posix_time.ptime(d, posix_time.time_duration(0, 0, 0, 2)) self.failUnless(t15 + posix_time.time_duration.unit() == t16) self.failUnless(t16 - posix_time.time_duration.unit() == t15) self.failUnless( posix_time.ptime(date_time.min_date_time) == posix_time.ptime( gregorian.date(1400, 1, 1), posix_time.time_duration( 0, 0, 0, 0))) self.failUnless( posix_time.ptime(date_time.max_date_time) == posix_time.ptime( gregorian.date(9999, 12, 31), posix_time.hours(24) - posix_time.time_duration.unit()))
def test_period(self): d1 = gregorian.date(2000,date_time.Jan,1) d2 = gregorian.date(2000,date_time.Jan,4) p1 = gregorian.date_period(d1,d2) p2 = gregorian.date_period(d1,gregorian.date_duration(3) ) self.failUnless( p1 == p2) self.failUnless( p1.begin() == d1) self.failUnless( p1.last() == d2-gregorian.date_duration(1) ) self.failUnless( p1.end() == d2) self.failUnless( p2.length() == gregorian.date_duration(3) ) self.failUnless( p1.contains(d1) ) self.failUnless( not p1.contains(d2) ) p3 = gregorian.date_period( gregorian.date(2000,date_time.Jan,4) , gregorian.date(2000,date_time.Feb,1) ) self.failUnless( not (p1 == p3) ) self.failUnless( p1 < p3) self.failUnless( p3 > p1) self.failUnless( p3 != p1) self.failUnless( p1.intersects(p1) ) self.failUnless( not p1.intersects(p3) ) self.failUnless( not p3.intersects(p1) ) p4 = gregorian.date_period(gregorian.date(1999,date_time.Dec,1), d2) self.failUnless( p1.intersects(p4) ) self.failUnless( p4.intersects(p1) ) p5 = gregorian.date_period(gregorian.date(1999,date_time.Dec,1) , gregorian.date(2000,date_time.Dec,31) ) self.failUnless( p1.intersects(p5) ) self.failUnless( p5.intersects(p1) ) p6 = gregorian.date_period(gregorian.date(2000,date_time.Jan,1) ,gregorian.date(2000,date_time.Dec,31) ) self.failUnless( p5.contains(p6) ) self.failUnless( p6.contains(p6) ) self.failUnless( not p6.contains(p5) ) fourDays = gregorian.date_duration(4) p1.shift(fourDays) shifted = gregorian.date_period(gregorian.date(2000,date_time.Jan,5) , gregorian.date(2000,date_time.Jan,8) ) self.failUnless( p1 == shifted) i1 = gregorian.date_period(gregorian.date(2000,date_time.Jan,5) , gregorian.date(2000,date_time.Jan,10) ) i2 = gregorian.date_period(gregorian.date(2000,date_time.Jan,1) , gregorian.date(2000,date_time.Jan,7) ) r1 = gregorian.date_period(gregorian.date(2000,date_time.Jan,5) , gregorian.date(2000,date_time.Jan,7) ) self.failUnless( i1.intersection(i2) == r1) self.failUnless( i2.intersection(i1) == r1) i3 = gregorian.date_period(gregorian.date(2000,date_time.Jan,1) , gregorian.date(2000,date_time.Jan,15) ) self.failUnless( i1.intersection(i3) == i1) self.failUnless( i3.intersection(i1) == i1) i4 = gregorian.date_period(gregorian.date(2000,date_time.Jan,7), gregorian.date(2000,date_time.Jan,10) ) i5 = gregorian.date_period(gregorian.date(2000,date_time.Jan,6) , gregorian.date(2000,date_time.Jan,9) ) self.failUnless( i1.intersection(i5) == i5) self.failUnless( i5.intersection(i1) == i5) self.failUnless( i2.intersection(i4).is_null() ) r3 = gregorian.date_period(gregorian.date(2000,date_time.Jan,1), gregorian.date(2000,date_time.Jan,10) ) self.failUnless( i1.merge(i2) == r3) self.failUnless( i2.merge(i4).is_null() ) r4 = gregorian.date_period(gregorian.date(2000,date_time.Jan,5), gregorian.date(2000,date_time.Jan,10) ) self.failUnless( i1.merge(i5) == r4) self.failUnless( i1.span(i2) == r3) self.failUnless( i2.span(i4) == r3) self.failUnless( i4.span(i2) == r3) self.failUnless( i3.span(i2) == i3) i6 = gregorian.date_period(gregorian.date(2000,date_time.Jan,1), gregorian.date(2000,date_time.Jan,2) ) self.failUnless( i6.span(i4) == r3) self.failUnless( i4.span(i6) == r3) bf_start = gregorian.date(2000,date_time.Jan,5) bf_end = gregorian.date(2000,date_time.Jan,10) bf_before = gregorian.date(2000,date_time.Jan,4) bf_after = gregorian.date(2000,date_time.Jan,11) bf_during = gregorian.date(2000, date_time.Jan, 7) bfp1 = gregorian.date_period(bf_start, bf_end) self.failUnless( not bfp1.is_before(bf_start) ) self.failUnless( bfp1.is_before(bf_end) ) self.failUnless( not bfp1.is_before(bfp1.last() )) self.failUnless( not bfp1.is_before(bf_before) ) self.failUnless( not bfp1.is_before(bf_during) ) self.failUnless( bfp1.is_before(bf_after) ) self.failUnless( not bfp1.is_after(bf_start) ) self.failUnless( not bfp1.is_after(bf_end) ) self.failUnless( not bfp1.is_after(bfp1.last() )) self.failUnless( bfp1.is_after(bf_before) ) self.failUnless( not bfp1.is_after(bf_during) ) self.failUnless( not bfp1.is_after(bf_after) ) adj1 = gregorian.date_period( gregorian.date(2000,date_time.Jan,5) , gregorian.date(2000,date_time.Jan,10) ) adj2 = gregorian.date_period (gregorian.date(2000,date_time.Jan,1), gregorian.date(2000,date_time.Jan,5) ) adj3 = gregorian.date_period(gregorian.date(2000,date_time.Jan,7), gregorian.date(2000,date_time.Jan,12) ) adj4 = gregorian.date_period(gregorian.date(2000,date_time.Jan,12), gregorian.date(2000,date_time.Jan,15) ) adj5 = gregorian.date_period(gregorian.date(2000,date_time.Jan,1), gregorian.date(2000,date_time.Jan,3) ) adj6 = gregorian.date_period(gregorian.date(2000,date_time.Jan,7), gregorian.date(2000,date_time.Jan,9) ) self.failUnless( adj1.is_adjacent(adj2) ) self.failUnless( adj2.is_adjacent(adj1) ) self.failUnless( not adj1.is_adjacent(adj3) ) self.failUnless( not adj3.is_adjacent(adj1) ) self.failUnless( not adj1.is_adjacent(adj4) ) self.failUnless( not adj4.is_adjacent(adj1) ) self.failUnless( not adj1.is_adjacent(adj5) ) self.failUnless( not adj5.is_adjacent(adj1) ) self.failUnless( not adj1.is_adjacent(adj6) ) self.failUnless( not adj6.is_adjacent(adj1) )
def test_date(self): self.failUnless( gregorian.date() == gregorian.date( date_time.not_a_date_time ) ) d1 = gregorian.date( 1900, 1, 1 ) d2 = gregorian.date( 2000, 1, 1 ) d3 = gregorian.date( 1900, 1, 1 ) d4 = gregorian.date( 2000, 12, 31 ) d4a = gregorian.date( 2000, date_time.Dec, 31 ) self.failUnless( d4 == d4a ) self.failUnless( d1.day().as_number() == 1 ) self.failUnless( d1.month().as_number() == 1 ) self.failUnless( d1.year().as_number() == 1900 ) self.failUnless( d4a.month().as_number() == 12 ) self.failUnless( d1 < d2 ) self.failUnless( not ( d1 < d1 ) ) self.failUnless( d1 <= d1 ) self.failUnless( d2 > d1 ) self.failUnless( not ( d1 > d1 ) ) self.failUnless( d1 >= d1 ) self.failUnless( d2 != d1 ) self.failUnless( d1 == d3 ) ymd = d1.year_month_day() self.failUnless( ymd.year.as_number() == 1900 ) self.failUnless( ymd.month.as_number() == 1 ) self.failUnless( ymd.day.as_number() == 1 ) answers = [ gregorian.date( 1900, date_time.Jan, 1 ) , gregorian.date( 1900, date_time.Jan, 4 ) , gregorian.date( 1900, date_time.Jan, 7 ) , gregorian.date( 1900, date_time.Jan, 10 ) , gregorian.date( 1900, date_time.Jan, 13 ) ] off = gregorian.date_duration( 3 ) d5 = gregorian.date( 1900, 1, 1 ) for i in range(5): self.failUnless( d5 == answers[i] ) d5 = d5 + off answers1 = [ gregorian.date(2000, 2 ,26) , gregorian.date(2000, 2 ,28) , gregorian.date(2000, date_time.Mar ,1 )] d8 = gregorian.date(2000, date_time.Feb, 26) for i in range(3): self.failUnless( d8 == answers1[i] ) d8 += gregorian.days(2) d6 = gregorian.date(2000,2,28) d7 = gregorian.date(2000,3,1) twoDays = gregorian.date_duration(2) negtwoDays = gregorian.date_duration(-2) zeroDays = gregorian.date_duration(0) self.failUnless( twoDays == d7 - d6 ) self.failUnless( negtwoDays == d6 - d7 ) self.failUnless( zeroDays == d6 - d6 ) self.failUnless( d6 + twoDays == d7 ) self.failUnless( d7 - twoDays == d6 ) self.failUnless( gregorian.date(1999,1,1) + gregorian.date_duration(365) == gregorian.date(2000,1,1) ) self.failUnless( gregorian.date(1999,1,1) + zeroDays == gregorian.date(1999,1,1) ) d = gregorian.date(2003, date_time.Oct, 31) dd = gregorian.date_duration(55) d += dd self.failUnless( d == gregorian.date(2003, date_time.Dec,25) ) d -= dd; self.failUnless( d == gregorian.date(2003, date_time.Oct,31) ) d = gregorian.date(2003,date_time.Oct, 31) dd1 = gregorian.date_duration( date_time.pos_infin) dd2 = gregorian.date_duration( date_time.neg_infin) dd3 = gregorian.date_duration( date_time.not_a_date_time) self.failUnless( d + dd1 == gregorian.date(date_time.pos_infin)) self.failUnless( d + dd2 == gregorian.date(date_time.neg_infin)) self.failUnless( d + dd3 == gregorian.date(date_time.not_a_date_time)) self.failUnless( d - dd1 == gregorian.date(date_time.neg_infin)) self.failUnless( d - dd2 == gregorian.date(date_time.pos_infin)) self.failUnless( d - dd3 == gregorian.date(date_time.not_a_date_time)) self.failUnless( gregorian.date(date_time.pos_infin) + dd1 == gregorian.date(date_time.pos_infin)) self.failUnless( gregorian.date(date_time.pos_infin) - dd1 == gregorian.date(date_time.not_a_date_time)) self.failUnless( gregorian.date(date_time.neg_infin) + dd1 == gregorian.date(date_time.not_a_date_time)) self.failUnless( gregorian.date(date_time.neg_infin) - dd1 == gregorian.date(date_time.neg_infin)) self.failUnlessRaises( Exception, lambda: gregorian.date( 2000, 1, 32 ) ) self.failUnlessRaises( Exception, lambda: gregorian.date( 2000, 1, 0 ) ) self.failUnlessRaises( Exception, lambda: gregorian.date( 2000, 2, 31 ) ) d15 = gregorian.date(1400,1,1) self.failUnless( d15.julian_day() == 2232400) self.failUnless( d15.modjulian_day() == -167601) d16 = gregorian.date(2004,2,29) self.failUnless( d16.julian_day() == 2453065) self.failUnless( d16.modjulian_day() == 53064) d31 = gregorian.date(2000, date_time.Jun, 1) self.failUnless( d31.week_number() == 22) d38 = gregorian.date(2001, 1, 1) self.failUnless( d38.day_of_year().as_number() == 1)
def test_date_duration(self): threeDays = gregorian.date_duration(3) twoDays = gregorian.date_duration(2) self.failUnless( threeDays == threeDays ) self.failUnless( threeDays == gregorian.date_duration(3) ) self.failUnless( threeDays != twoDays ) self.failUnless( twoDays < threeDays ) self.failUnless( not ( threeDays < twoDays ) ) self.failUnless( not ( threeDays < threeDays ) ) self.failUnless( not ( threeDays > threeDays ) ) self.failUnless( threeDays >= threeDays ) self.failUnless( not ( twoDays >= threeDays ) ) self.failUnless( twoDays + threeDays == gregorian.date_duration(5) ) fiveDays = gregorian.date_duration(3) fiveDays += twoDays self.failUnless( fiveDays == gregorian.date_duration(5) ) derivedOneDay = threeDays - twoDays self.failUnless( twoDays - threeDays == gregorian.date_duration(-1) ) oneDay = gregorian.date_duration(1) self.failUnless( oneDay == derivedOneDay ) fiveDaysDerived = gregorian.date_duration( 10 ) fiveDaysDerived -= fiveDays self.failUnless( fiveDaysDerived == fiveDays) oneDay = twoDays / 2 self.failUnless( oneDay.days() == 1 ) hundred = gregorian.date_duration(100) hundred /= -10 self.failUnless( hundred.days() == -10 and hundred.is_negative()) self.failUnless( gregorian.date_duration( -gregorian.date_duration( 123 ).days() ).days() == -123 ) pos_dur = gregorian.date_duration(123) neg_dur = -pos_dur self.failUnless( neg_dur.days() == -123) pi_dur = gregorian.date_duration(date_time.pos_infin) ni_dur = gregorian.date_duration(date_time.neg_infin) nd_dur = gregorian.date_duration(date_time.not_a_date_time) self.failUnless( pi_dur + ni_dur == nd_dur) self.failUnless( ni_dur / 3 == ni_dur) self.failUnless( pi_dur + hundred == pi_dur) self.failUnless( -pi_dur == ni_dur)