Ticket #562: WikiCalendar_inc_dec_month_and_year.patch

File WikiCalendar_inc_dec_month_and_year.patch, 2.2 kB (added by taa, 2 years ago)

Patch

  • WikiCalendar.py

    old new  
    1010# 
    1111# Author: Matthew Good <trac@matt-good.net> 
    1212# Month/Year navigation by: Jan Finell <finell@cenix-bioscience.com> 
     13# Month/Year increment/decrement parameters by: Tony Abou-Assaleh <taa@acm.org> 
    1314 
    1415import time 
    1516import calendar 
     
    5152    # find out whether use http param, current or macro param year/month 
    5253     
    5354    if http_param_year == "": 
    54         # not clicked on a prev or next button 
    55         if len(args) >= 1 and args[0] <> "*": 
    56             # year given in macro parameters 
    57             year = int(args[0]) 
    58         else: 
    59             # use current year 
    60             year = today.tm_year 
     55        # use current year 
     56        year = today.tm_year 
    6157    else: 
    6258        # year in http params (clicked by user) overrides everything 
    6359        year = int(http_param_year) 
    64      
     60 
     61    # not clicked on a prev or next button 
     62    if len(args) >= 1: 
     63        if args[0][0] == "*": 
     64                pass 
     65        elif args[0][0] in ("-", "+"): 
     66                year += int(args[0]) 
     67        else: 
     68                # year given in macro parameters 
     69                year = int(args[0]) 
     70 
    6571    if http_param_month == "": 
    66         # not clicked on a prev or next button 
    67         if len(args) >= 2 and args[1] <> "*": 
    68             # month given in macro parameters 
    69             month = int(args[1]) 
    70         else: 
    71             # use current month 
    72             month = today.tm_mon 
     72        # use current month 
     73        month = today.tm_mon 
    7374    else: 
    7475        # month in http params (clicked by user) overrides everything 
    7576        month = int(http_param_month) 
    76      
     77 
     78    # not clicked on a prev or next button 
     79    if len(args) >= 2: 
     80        if args[1][1] == "*": 
     81                pass 
     82        elif args[1][1] in ("-", "+"): 
     83                month += int(args[1]) 
     84        else: 
     85                # month given in macro parameters 
     86                month = int(args[1]) 
     87 
     88    # handle month > 12 and month < 1, must shift to month  
     89    # range from [1,12] to [0,11] and back 
     90    year += (month-1) / 12 
     91    month = (month+11) % 12 + 1 
     92 
    7793    showbuttons = 1 
    7894    if len(args) >= 3: 
    7995        showbuttons = bool(args[2]=="True" or args[2]=="true" or args[2]=="no" or args[2]=="0")