utils.py
branchtls-sprint
changeset 1751 59e9a4f5bfea
parent 1711 182536159750
child 1977 606923dff11b
equal deleted inserted replaced
1750:9df5e65c5f79 1751:59e9a4f5bfea
    29     assert isinstance(somedate, date), repr(somedate)
    29     assert isinstance(somedate, date), repr(somedate)
    30     return somedate
    30     return somedate
    31 
    31 
    32 def todatetime(somedate):
    32 def todatetime(somedate):
    33     """return a date from a date (leaving unchanged) or a datetime"""
    33     """return a date from a date (leaving unchanged) or a datetime"""
    34     if isinstance(somedate, date):
    34     # take care, datetime is a subclass of date
    35         return datetime(somedate.year, somedate.month, somedate.day)
    35     if isinstance(somedate, datetime):
    36     assert isinstance(somedate, datetime), repr(somedate)
    36         return somedate
    37     return somedate
    37     assert isinstance(somedate, date), repr(somedate)
       
    38     return datetime(somedate.year, somedate.month, somedate.day)
    38 
    39 
    39 ONEDAY = timedelta(days=1)
    40 ONEDAY = timedelta(days=1)
    40 ONEWEEK = timedelta(days=7)
    41 ONEWEEK = timedelta(days=7)
    41 
    42 
    42 def days_in_month(date_):
    43 def days_in_month(date_):