Changeset - 7883fe1d5e06
[Not reviewed]
0 1 0
Lance Edgar - 8 years ago 2016-04-28 18:12:28
ledgar@sacfoodcoop.com
Add `time.get_sunday()` convenience function
1 file changed with 11 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/time.py
Show inline comments
 
@@ -116,3 +116,14 @@ def make_utc(time, tzinfo=False):
 
    if tzinfo:
 
        return utctime
 
    return utctime.replace(tzinfo=None)
 

	
 

	
 
def get_sunday(date):
 
    """
 
    Return a ``datetime.date`` instance corresponding to Sunday of the given
 
    week, according to the ``date`` parameter.
 
    """
 
    weekday = date.weekday()
 
    if weekday == 6: # Sunday
 
        return date
 
    return date - datetime.timedelta(days=weekday + 1)
0 comments (0 inline, 0 general)