Django

Code

Ticket #992: date_based.diff

File date_based.diff, 0.8 kB (added by ubernostrum, 3 years ago)

Patch to use first day of next month instead of last day of month

  • django/views/generic/date_based.py

    old new  
    108108    now = datetime.datetime.now() 
    109109    # Calculate first and last day of month, for use in a date-range lookup. 
    110110    first_day = date.replace(day=1) 
    111     last_day = date 
    112     for i in (31, 30, 29, 28): 
    113         try: 
    114             last_day = last_day.replace(day=i) 
    115         except ValueError: 
    116             continue 
    117         else: 
    118             break 
     111    last_day = first_day.replace(month=(first_day.month+1)%12) 
    119112    lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)} 
    120113    # Only bother to check current date if the month isn't in the past. 
    121114    if last_day >= now.date():