Exemplo n.º 1
0
def meetup_day(year, month, day_of_week, signifier):
    if day_of_week == 'Monday':
        day_of_week = 0
    elif day_of_week == 'Tuesday':
        day_of_week = 1
    elif day_of_week == 'Wednesday':
        day_of_week = 2
    elif day_of_week == 'Thursday':
        day_of_week = 3
    elif day_of_week == 'Friday':
        day_of_week = 4
    elif day_of_week == 'Saturday':
        day_of_week = 5
    else:  #day of week == Sunday
        day_of_week = 6

    if signifier[0].isdigit():
        first_day = date(year, month, 1).weekday()

        offset = (day_of_week - first_day) + 1
        if offset < 1:
            offset += 7

        if signifier == '1st':
            return date(year, month, offset)
        elif signifier == '2nd':
            return date(year, month, offset + 7)
        elif signifier == '3rd':
            return date(year, month, offset + 14)
        else:  #signifier == '4th'
            return date(year, month, offset + 21)

    elif signifier == 'last':
        if month in [
                'January', 'March', 'May', 'July', 'August', 'October',
                'December'
        ]:
            len_of_month = 31
        elif month in ['April', 'June', 'September', 'November']:
            len_of_month = 30
        else:  #month == February
            if is_leap_year(year):
                len_of_month = 29
            else:
                len_of_month = 28

        last_day = date(year, month, len_of_month).weekday()
        offset = last_day - day_of_week

        #works with tests but could easily return faulty date - what's a better way to do this?
        return date(year, month, len_of_month - offset)

    else:  #signifer == 'teenth'
        the_13th = date(year, month, 13).weekday()

        offset = (day_of_week - the_13th) + 1
        if offset < 1:
            offset += 7
        return date(year, month, offset + 12)
def add_gigasecond_bad(dtobj):
	day0 = 0
	y = dtobj.year
	m = dtobj.month
	day = dtobj.day
	while (day0-day)<gig2day:
		if is_leap_year(y):
			year = lyear
		else:
			year = nyear
		for month in range(m,13):
			if day0 + year[month] >= gig2day:
				return date(y,month,gig2day-day0)
			day0 += year[month]
			if month >= 12:
				m = 1
		y += 1
Exemplo n.º 3
0
 def test_year(self):
     self.assertTrue(is_leap_year(1896))
Exemplo n.º 4
0
 def test_is_leap_year(self):
     self.assertFalse(is_leap_year(2015))
Exemplo n.º 5
0
 def test_leap_year(self):
     self.assertIs(is_leap_year(1996), True)
Exemplo n.º 6
0
 def test_non_leap_year(self):
     self.assertIs(is_leap_year(1997), False)
Exemplo n.º 7
0
 def test_century(self):
     self.assertIs(is_leap_year(1900), False)
Exemplo n.º 8
0
 def test_exceptional_century2(self):
     self.assertIs(is_leap_year(2000), True)
Exemplo n.º 9
0
 def test_leap_year(self):
     self.assertIs(is_leap_year(1996), True)
Exemplo n.º 10
0
 def test_non_leap_year(self):
     self.assertFalse(is_leap_year(1997))
Exemplo n.º 11
0
 def test_century(self):
     self.assertFalse(is_leap_year(1900))
Exemplo n.º 12
0
 def test_leap_year(self):
     self.assertTrue(is_leap_year(1996))
Exemplo n.º 13
0
 def test_non_leap_even_year(self):
     self.assertFalse(is_leap_year(1998))
Exemplo n.º 14
0
 def test_is_leap_year(self):
     self.assertFalse(is_leap_year(2015))
Exemplo n.º 15
0
 def test_is_leap_year(self):
     self.assertIs(is_leap_year(2016), True)
     self.assertFalse(is_leap_year(1994));
     self.assertIs(is_leap_year(1492), False)
     self.assertFalse(is_leap_year(1983));
Exemplo n.º 16
0
 def test_century(self):
     self.assertIs(is_leap_year(1900), False)
Exemplo n.º 17
0
 def test_century(self):
     self.assertFalse(is_leap_year(1900))
Exemplo n.º 18
0
 def test_exceptional_century(self):
     self.assertIs(is_leap_year(2400), True)
Exemplo n.º 19
0
 def test_exceptional_century(self):
     self.assertTrue(is_leap_year(2400))
Exemplo n.º 20
0
 def test_non_leap_year(self):
     self.assertIs(is_leap_year(1997), False)
Exemplo n.º 21
0
 def test_leap_year(self):
     self.assertTrue(is_leap_year(abcd))