Changeset 2516
- Timestamp:
- 07/23/07 14:29:41 (1 year ago)
- Files:
-
- calendarplugin/0.10/azcalendar/azcalendar.py (modified) (5 diffs)
- calendarplugin/0.10/azcalendar/caltools.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
calendarplugin/0.10/azcalendar/azcalendar.py
r2515 r2516 67 67 req.perm.assert_permission('CAL_VIEW') 68 68 69 def get_week(date):70 # If there is a simpler way to do this, let me know. For now...71 d_year, d_doy, d_dow = date[0], date[-2], date[-3]72 73 doy_start = d_doy - d_dow74 y_start = d_year75 if doy_start < 1:76 y_start -= 177 doy_start += 365 + int (calendar.isleap (y_start))78 79 doy_end = d_doy - d_dow + 780 y_end = d_year81 if doy_end > 365 + int (calendar.isleap (y_end)):82 doy_end -= 365 + int (calendar.isleap (y_end))83 y_end += 184 85 week_start = time.strptime (str(y_start) + str(doy_start), "%Y%j")86 week_end = time.strptime (str(y_end) + str(doy_end), "%Y%j")87 return week_start, week_end88 89 def get_month_range(date):90 d_year, d_month = date[0], date[1]91 month_start = tuple([d_year, d_month, 1] + [0 for _ in date[3:]])92 d_month = d_month + 193 if d_month > 12:94 d_year += 195 d_month = 196 month_end = tuple([d_year, d_month, 1] + [0 for _ in date[3:]])97 return month_start, month_end98 99 def relative_day(week_start, which_day):100 d_year, d_doy = week_start[0], week_start[-2]101 doy = d_doy + which_day102 if doy < 1:103 d_year -= 1104 doy += 365 + int (calendar.isleap (d_year))105 elif doy > 365 + int (calendar.isleap (d_year)):106 doy -= 365 + int (calendar.isleap (d_year))107 d_year += 1108 day = time.strptime (str(d_year) + str(doy), "%Y%j")109 return day110 111 69 def stamp_dow (stamp): 112 70 return time.localtime(stamp)[6] … … 132 90 133 91 cweek = [[] for _ in xrange(7)] 134 week_range = get_week(date)92 week_range = caltools.get_week_range(date) 135 93 bg, en = time.mktime(week_range[0]), time.mktime(week_range[1]) 136 94 for ev in Event.events_between (self.env, bg, en,req.authname): … … 146 104 147 105 for d in xrange (len (day_layouts)): 148 today = relative_day(week_start, d)106 today = caltools.relative_day(week_start, d) 149 107 today_stamp = time.mktime (today) 150 108 tomorrow_stamp = today_stamp + 24 * 60 * 60 … … 183 141 184 142 display_months = [] 185 dm_year, dm_month = get_month_range (week_start)[0][:2]143 dm_year, dm_month = caltools.get_month_range (week_start)[0][:2] 186 144 187 145 prev_year, prev_month, prev_day = date[:3] … … 200 158 201 159 for i in range(3): 202 month_range = get_month_range (tuple([dm_year, dm_month, 1] + [0 for i in range(6)]))160 month_range = caltools.get_month_range (tuple([dm_year, dm_month, 1] + [0 for i in range(6)])) 203 161 interesting_days = {} 204 162 calendarplugin/0.10/azcalendar/caltools.py
r2508 r2516 20 20 return (tm_year, tm_mon, tm_day) + struct_time[3:] 21 21 22 # Each format may be either a string, or a tuple (string, callback). 23 # strptime result of the first matching format is returned. If the 24 # format has assigned a callback, it is first called with the result 25 # of strptime, and result of the callback is then returned. 22 def relative_day(week_start, which_day): 23 d_year, d_doy = week_start[0], week_start[-2] 24 doy = d_doy + which_day 25 if doy < 1: 26 d_year -= 1 27 doy += 365 + int (calendar.isleap (d_year)) 28 elif doy > 365 + int (calendar.isleap (d_year)): 29 doy -= 365 + int (calendar.isleap (d_year)) 30 d_year += 1 31 day = time.strptime (str(d_year) + str(doy), "%Y%j") 32 return day 33 34 26 35 def strptimeopt (string, *formats): 36 """ 37 Each format may be either a string, or a tuple (string, callback). 38 strptime result of the first matching format is returned. If the 39 format has assigned a callback, it is first called with the result 40 of strptime, and result of the callback is then returned. 41 """ 42 27 43 import types 28 44 assert formats, "Non-empty list of formats required." … … 59 75 60 76 return begin_time, end_time, begin_stamp, end_stamp 77 78 def get_week_range(date): 79 """ 80 Answer the tuple (start, end) with timestamps of start and end of 81 the week that contains given date. 82 """ 83 84 # If there is a simpler way to do this, let me know. For now... 85 d_year, d_doy, d_dow = date[0], date[-2], date[-3] 86 87 doy_start = d_doy - d_dow 88 y_start = d_year 89 if doy_start < 1: 90 y_start -= 1 91 doy_start += 365 + int (calendar.isleap (y_start)) 92 93 doy_end = d_doy - d_dow + 7 94 y_end = d_year 95 if doy_end > 365 + int (calendar.isleap (y_end)): 96 doy_end -= 365 + int (calendar.isleap (y_end)) 97 y_end += 1 98 99 week_start = time.strptime (str(y_start) + str(doy_start), "%Y%j") 100 week_end = time.strptime (str(y_end) + str(doy_end), "%Y%j") 101 return week_start, week_end 102 103 def get_month_range(date): 104 """ 105 Answer the tuple (start, end) with timestamps of start and end of 106 the month that contains given date. 107 """ 108 109 d_year, d_month = date[0], date[1] 110 month_start = tuple([d_year, d_month, 1] + [0 for _ in date[3:]]) 111 d_month = d_month + 1 112 if d_month > 12: 113 d_year += 1 114 d_month = 1 115 month_end = tuple([d_year, d_month, 1] + [0 for _ in date[3:]]) 116 return month_start, month_end