1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - MoinDateSupport library (derived from EventAggregatorSupport) 4 5 @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 from MoinSupport import * 10 11 # User interface functions. 12 13 def getParameterDate(arg): 14 15 "Interpret 'arg', recognising keywords and simple arithmetic operations." 16 17 n = None 18 19 if not arg: 20 return None 21 22 elif arg.startswith("current"): 23 date = getCurrentDate() 24 if len(arg) > 8: 25 n = int(arg[7:]) 26 27 elif arg.startswith("yearstart"): 28 date = Date((getCurrentYear(), 1, 1)) 29 if len(arg) > 10: 30 n = int(arg[9:]) 31 32 elif arg.startswith("yearend"): 33 date = Date((getCurrentYear(), 12, 31)) 34 if len(arg) > 8: 35 n = int(arg[7:]) 36 37 else: 38 date = getDate(arg) 39 40 if n is not None: 41 date = date.day_update(n) 42 43 return date 44 45 def getParameterMonth(arg): 46 47 "Interpret 'arg', recognising keywords and simple arithmetic operations." 48 49 n = None 50 51 if arg is None: 52 return None 53 54 elif arg.startswith("current"): 55 date = getCurrentMonth() 56 if len(arg) > 8: 57 n = int(arg[7:]) 58 59 elif arg.startswith("yearstart"): 60 date = Month((getCurrentYear(), 1)) 61 if len(arg) > 10: 62 n = int(arg[9:]) 63 64 elif arg.startswith("yearend"): 65 date = Month((getCurrentYear(), 12)) 66 if len(arg) > 8: 67 n = int(arg[7:]) 68 69 else: 70 date = getMonth(arg) 71 72 if n is not None: 73 date = date.month_update(n) 74 75 return date 76 77 def getFormDate(request, calendar_name, argname): 78 79 """ 80 Return the date from the 'request' for the calendar with the given 81 'calendar_name' using the parameter having the given 'argname'. 82 """ 83 84 arg = getQualifiedParameter(request, calendar_name, argname) 85 return getParameterDate(arg) 86 87 def getFormMonth(request, calendar_name, argname): 88 89 """ 90 Return the month from the 'request' for the calendar with the given 91 'calendar_name' using the parameter having the given 'argname'. 92 """ 93 94 arg = getQualifiedParameter(request, calendar_name, argname) 95 return getParameterMonth(arg) 96 97 def getFormDateTriple(request, yeararg, montharg, dayarg): 98 99 """ 100 Return the date from the 'request' for the calendar with the given 101 'calendar_name' using the parameters having the given 'yeararg', 'montharg' 102 and 'dayarg' names. 103 """ 104 105 year = getParameter(request, yeararg) 106 month = getParameter(request, montharg) 107 day = getParameter(request, dayarg) 108 if year and month and day: 109 return Date((int(year), int(month), int(day))) 110 else: 111 return None 112 113 def getFormMonthPair(request, yeararg, montharg): 114 115 """ 116 Return the month from the 'request' for the calendar with the given 117 'calendar_name' using the parameters having the given 'yeararg' and 118 'montharg' names. 119 """ 120 121 year = getParameter(request, yeararg) 122 month = getParameter(request, montharg) 123 if year and month: 124 return Month((int(year), int(month))) 125 else: 126 return None 127 128 def getFullDateLabel(request, date): 129 130 """ 131 Return the full month plus year label using the given 'request' and 132 'year_month'. 133 """ 134 135 if not date: 136 return "" 137 138 _ = request.getText 139 year, month, day = date.as_tuple()[:3] 140 start_weekday, number_of_days = date.month_properties() 141 weekday = (start_weekday + day - 1) % 7 142 day_label = _(getDayLabel(weekday)) 143 month_label = _(getMonthLabel(month)) 144 return "%s %s %s %s" % (day_label, day, month_label, year) 145 146 def getFullMonthLabel(request, year_month): 147 148 """ 149 Return the full month plus year label using the given 'request' and 150 'year_month'. 151 """ 152 153 if not year_month: 154 return "" 155 156 _ = request.getText 157 year, month = year_month.as_tuple()[:2] 158 month_label = _(getMonthLabel(month)) 159 return "%s %s" % (month_label, year) 160 161 # vim: tabstop=4 expandtab shiftwidth=4