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