Beispiel #1
0
    def test_dst_transition_day_rule(self):
        rule1 = local_time.partial_date_dst_rule( 
                    gregorian.partial_date(30, date_time.Apr)
                    , gregorian.partial_date(30, date_time.Oct))
        self.failUnless( rule1.start_day(2001) == gregorian.date(2001, date_time.Apr, 30))
        self.failUnless( rule1.end_day(2001) == gregorian.date(2001, date_time.Oct, 30))
    
        rule2 = local_time.first_last_dst_rule(
                    local_time.first_last_dst_rule.start_rule(date_time.Sunday, date_time.Apr)
                    , local_time.first_last_dst_rule.end_rule(date_time.Sunday, date_time.Oct))

        self.failUnless( rule2.start_day(2001) == gregorian.date(2001, date_time.Apr, 1))
        self.failUnless( rule2.end_day(2001) == gregorian.date(2001, date_time.Oct, 28))

        rule3 = local_time.last_last_dst_rule(
                    local_time.last_last_dst_rule.start_rule(date_time.Sunday, date_time.Mar)
                    , local_time.last_last_dst_rule.end_rule(date_time.Sunday, date_time.Oct))

        self.failUnless( rule3.start_day(2001) == gregorian.date(2001, date_time.Mar, 25))
        self.failUnless( rule3.end_day(2001) == gregorian.date(2001, date_time.Oct, 28) )
  
        nkday = gregorian.nth_kday_of_month
        rule4 = local_time.nth_last_dst_rule(
                    local_time.nth_last_dst_rule.start_rule(nkday.first, date_time.Sunday, date_time.Mar)
                    , local_time.nth_last_dst_rule.end_rule(date_time.Sunday, date_time.Oct))
  
        self.failUnless( rule4.start_day(2001) == gregorian.date(2001, date_time.Mar, 4))
        self.failUnless( rule4.end_day(2001) == gregorian.date(2001, date_time.Oct, 28))

        rule5 = local_time.nth_kday_dst_rule(
                    local_time.nth_kday_dst_rule.start_rule(nkday.first, date_time.Sunday, date_time.Mar)
                    , local_time.nth_kday_dst_rule.end_rule(nkday.fourth, date_time.Sunday, date_time.Oct))
  
        self.failUnless( rule5.start_day(2001) == gregorian.date(2001, date_time.Mar, 4))
        self.failUnless( rule5.end_day(2001) == gregorian.date(2001, date_time.Oct, 28))
Beispiel #2
0
    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))
Beispiel #3
0
    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))
Beispiel #4
0
    def test_custom_time_zone( self ):
        rule1 = local_time.partial_date_dst_rule(
                    gregorian.partial_date(30, date_time.Apr)
                    , gregorian.partial_date(30, date_time.Oct))
  
        rule2 = local_time.first_last_dst_rule(
                    local_time.first_last_dst_rule.start_rule( date_time.Sunday, date_time.Apr)
                    , local_time.first_last_dst_rule.end_rule( date_time.Sunday, date_time.Oct))
        
        rule3 = local_time.last_last_dst_rule(
                    local_time.last_last_dst_rule.start_rule(date_time.Sunday, date_time.Mar)
                    , local_time.last_last_dst_rule.end_rule(date_time.Sunday, date_time.Oct))
        
        rule4 = None

        pst = local_time.time_zone_names( "Pacific Standard Time"
                                          , "PST"
                                          , "Pacific Daylight Time" 
                                          , "PDT" )
        
        mst = local_time.time_zone_names( "Mountain Standard Time"
                                          , "MST"
                                          , "" 
                                          , "" )
  
        of = local_time.dst_adjustment_offsets( posix_time.hours(1)
                                                , posix_time.hours(2)
                                                , posix_time.hours(2))
        of2 = local_time.dst_adjustment_offsets( posix_time.hours(0)
                                                 , posix_time.hours(0)
                                                 , posix_time.hours(0))

        tz1 = local_time.custom_time_zone(pst, posix_time.hours(-8), of, rule1)
        tz2 = local_time.custom_time_zone(pst, posix_time.hours(-8), of, rule2)
        tz3 = local_time.custom_time_zone(pst, posix_time.hours(-8), of, rule3)
        tz4 = local_time.custom_time_zone(mst, posix_time.hours(-7), of2, rule4)


        self.failUnless( tz1.dst_zone_abbrev() == "PDT" )
        self.failUnless( tz1.std_zone_abbrev() == "PST" )
        self.failUnless( tz1.std_zone_name() == "Pacific Standard Time" )
        self.failUnless( tz1.dst_zone_name() == "Pacific Daylight Time" )
        
        self.failUnless( tz1.dst_offset() == posix_time.hours(1) )
        self.failUnless( tz1.base_utc_offset() == posix_time.hours(-8) )
        self.failUnless( tz1.has_dst() )
        
        self.failUnless( tz1.dst_local_start_time(2003) 
                         == posix_time.ptime( gregorian.date(2003, date_time.Apr,30)
                                              , posix_time.hours(2) ) )
        
        self.failUnless( tz1.dst_local_end_time(2003) 
                         == posix_time.ptime( gregorian.date(2003, date_time.Oct,30)
                                              , posix_time.hours(2) ) )
        
        
        self.failUnless( tz1.to_posix_string() == "PST-08PDT+01,120/02:00,303/02:00")
        self.failUnless( tz2.to_posix_string() == "PST-08PDT+01,M4.1.0/02:00,M10.5.0/02:00")
        self.failUnless( tz3.to_posix_string() == "PST-08PDT+01,M3.5.0/02:00,M10.5.0/02:00")
        self.failUnless( tz4.to_posix_string() == "MST-07")
        
        self.failUnless( not tz4.has_dst() )
        
        self.failUnless( tz4.dst_local_start_time(2005) 
                         == posix_time.ptime( date_time.not_a_date_time ) )
        
        self.failUnless( tz4.dst_local_end_time(2005) 
                         == posix_time.ptime( date_time.not_a_date_time ) )