def test_greg_day(self): self.failUnless( gregorian.greg_day(1).as_number() == 1 ) self.failUnlessRaises( Exception, lambda: gregorian.greg_day(0) ) self.failUnless( gregorian.greg_day.min() == 1 ) self.failUnless( gregorian.greg_day.max() == 31 ) sunday = gregorian.greg_weekday(0) monday = gregorian.greg_weekday(1) self.failUnless( sunday.as_short_string() == "Sun" ) self.failUnlessRaises( Exception, lambda: gregorian.greg_day_of_year_rep(367) )
def test_greg_day(self): self.failUnless(gregorian.greg_day(1).as_number() == 1) self.failUnlessRaises(Exception, lambda: gregorian.greg_day(0)) self.failUnless(gregorian.greg_day.min() == 1) self.failUnless(gregorian.greg_day.max() == 31) sunday = gregorian.greg_weekday(0) monday = gregorian.greg_weekday(1) self.failUnless(sunday.as_short_string() == "Sun") self.failUnlessRaises(Exception, lambda: gregorian.greg_day_of_year_rep(367))
def test_generators(self): pd1 =gregorian.partial_date(1, date_time.Jan) d = pd1.get_date(2000) self.failUnless( pd1.to_string() == "0" ) self.failUnless( gregorian.date(2000,1,1) == d) pd2 = gregorian.partial_date(1, date_time.Feb) self.failUnless( pd1 == pd1) self.failUnless( not(pd1 == pd2) ) self.failUnless( not(pd2 == pd1) ) self.failUnless( not(pd1 < pd1) ) self.failUnless( pd1 < pd2) self.failUnless( not(pd2 < pd1) ) lastkday = gregorian.last_day_of_the_week_in_month lsif = lastkday( date_time.Sunday, date_time.Feb) self.failUnless( gregorian.date(2002, date_time.Feb,24) == lsif.get_date(2002)) self.failUnless( lsif.to_string() == "M2.5.0" ) firstkday = gregorian.first_day_of_the_week_in_month fsif = firstkday(date_time.Sunday, date_time.Feb) self.failUnless( gregorian.date(2002, date_time.Feb,3) == fsif.get_date(2002)) self.failUnless( fsif.to_string() == "M2.1.0" ) firstkdayafter = gregorian.first_day_of_the_week_after fkaf = firstkdayafter(date_time.Monday) self.failUnless( gregorian.date(2002, date_time.Feb,4) == fkaf.get_date( gregorian.date(2002,date_time.Feb,1))) self.failUnless( '2002-Feb-04' == to_simple_string( fkaf.get_date( gregorian.date(2002,date_time.Feb,1)))) firstkdaybefore = gregorian.first_day_of_the_week_before fkbf = firstkdaybefore(date_time.Monday) self.failUnless( '2002-Feb-11' == to_simple_string(fkaf.get_date(gregorian.date(2002,date_time.Feb,10)))) self.failUnless( gregorian.date(2002,date_time.Feb,4) == fkbf.get_date(gregorian.date(2002,date_time.Feb,10))) nthkdayofmonth = gregorian.nth_day_of_the_week_in_month; nkd1 = nthkdayofmonth(nthkdayofmonth.third, date_time.Sunday, date_time.Jul) self.failUnless( gregorian.date(1969, date_time.Jul, 20) == nkd1.get_date(1969)) self.failUnless( nkd1.to_string() == "M7.3.0" ) saturday = gregorian.date(2003,date_time.Feb,8) sund = gregorian.greg_weekday(date_time.Sunday) self.failUnless( gregorian.days_until_weekday(saturday, sund) == gregorian.days(1)) self.failUnless( gregorian.days_before_weekday(saturday, sund) == gregorian.days(6)) self.failUnless( gregorian.next_weekday(saturday, sund)== gregorian.date(2003,date_time.Feb,9)) self.failUnless( gregorian.previous_weekday(saturday, sund)== gregorian.date(2003,date_time.Feb,2))
def test_generators(self): pd1 = gregorian.partial_date(1, date_time.Jan) d = pd1.get_date(2000) self.failUnless(pd1.to_string() == "0") self.failUnless(gregorian.date(2000, 1, 1) == d) pd2 = gregorian.partial_date(1, date_time.Feb) self.failUnless(pd1 == pd1) self.failUnless(not (pd1 == pd2)) self.failUnless(not (pd2 == pd1)) self.failUnless(not (pd1 < pd1)) self.failUnless(pd1 < pd2) self.failUnless(not (pd2 < pd1)) lastkday = gregorian.last_day_of_the_week_in_month lsif = lastkday(date_time.Sunday, date_time.Feb) self.failUnless( gregorian.date(2002, date_time.Feb, 24) == lsif.get_date(2002)) self.failUnless(lsif.to_string() == "M2.5.0") firstkday = gregorian.first_day_of_the_week_in_month fsif = firstkday(date_time.Sunday, date_time.Feb) self.failUnless( gregorian.date(2002, date_time.Feb, 3) == fsif.get_date(2002)) self.failUnless(fsif.to_string() == "M2.1.0") firstkdayafter = gregorian.first_day_of_the_week_after fkaf = firstkdayafter(date_time.Monday) self.failUnless( gregorian.date(2002, date_time.Feb, 4) == fkaf.get_date( gregorian.date(2002, date_time.Feb, 1))) self.failUnless('2002-Feb-04' == to_simple_string( fkaf.get_date(gregorian.date(2002, date_time.Feb, 1)))) firstkdaybefore = gregorian.first_day_of_the_week_before fkbf = firstkdaybefore(date_time.Monday) self.failUnless('2002-Feb-11' == to_simple_string( fkaf.get_date(gregorian.date(2002, date_time.Feb, 10)))) self.failUnless( gregorian.date(2002, date_time.Feb, 4) == fkbf.get_date( gregorian.date(2002, date_time.Feb, 10))) nthkdayofmonth = gregorian.nth_day_of_the_week_in_month nkd1 = nthkdayofmonth(nthkdayofmonth.third, date_time.Sunday, date_time.Jul) self.failUnless( gregorian.date(1969, date_time.Jul, 20) == nkd1.get_date(1969)) self.failUnless(nkd1.to_string() == "M7.3.0") saturday = gregorian.date(2003, date_time.Feb, 8) sund = gregorian.greg_weekday(date_time.Sunday) self.failUnless( gregorian.days_until_weekday(saturday, sund) == gregorian.days(1)) self.failUnless( gregorian.days_before_weekday(saturday, sund) == gregorian.days(6)) self.failUnless( gregorian.next_weekday(saturday, sund) == gregorian.date( 2003, date_time.Feb, 9)) self.failUnless( gregorian.previous_weekday(saturday, sund) == gregorian.date( 2003, date_time.Feb, 2))