35 return datetime(somedate.year, somedate.month, somedate.day) |
35 return datetime(somedate.year, somedate.month, somedate.day) |
36 assert isinstance(somedate, datetime), repr(somedate) |
36 assert isinstance(somedate, datetime), repr(somedate) |
37 return somedate |
37 return somedate |
38 |
38 |
39 ONEDAY = timedelta(days=1) |
39 ONEDAY = timedelta(days=1) |
|
40 ONEWEEK = timedelta(days=7) |
40 |
41 |
41 def days_in_month(date_): |
42 def days_in_month(date_): |
42 return monthrange(date_.year, date_.month)[1] |
43 return monthrange(date_.year, date_.month)[1] |
43 |
44 |
44 def previous_month(date_): |
45 def previous_month(date_, nbmonth=1): |
45 return first_day(date_) - ONEDAY |
46 while nbmonth: |
46 |
47 date_ = first_day(date_) - ONEDAY |
47 def next_month(date_): |
48 nbmonth -= 1 |
48 return last_day(date_) + ONEDAY |
49 return date_ |
|
50 |
|
51 def next_month(date_, nbmonth=1): |
|
52 while nbmonth: |
|
53 date_ = last_day(date_) + ONEDAY |
|
54 nbmonth -= 1 |
|
55 return date_ |
49 |
56 |
50 def first_day(date_): |
57 def first_day(date_): |
51 return date(date_.year, date_.month, 1) |
58 return date(date_.year, date_.month, 1) |
52 |
59 |
53 def last_day(date_): |
60 def last_day(date_): |