webcalendar

Check-in [77276890af]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Handle multiple days of the week under a weekly repeat
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:77276890af070dbde2aa320b8918b6aeba66a78d124c2b5fab6a8cdfa415dc9a
User & Date: ajv-899-334-8894@vsta.org 2017-06-09 00:26:06
Context
2017-06-10
17:15
Handle event count on monthly by day. Handle display when there are no timed events. check-in: cb0f89b99e user: ajv-899-334-8894@vsta.org tags: master, trunk
2017-06-09
00:26
Handle multiple days of the week under a weekly repeat check-in: 77276890af user: ajv-899-334-8894@vsta.org tags: master, trunk
2017-06-01
03:35
Another distro file I should include check-in: 56631fa23b user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to cgi-bin/webcal.py.

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
234
235
236
237
238
239
240
241
242
243
244




245


246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269










270
271
272
273
274
275
276
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
    if res:
	return res
    return cmp(tm1.tm_sec, tm2.tm_sec)

# Tell if tm2 overlaps at all with tm1's range
# (tm2 is assumed to lie at or later than tm1 due to pre-ordering.)
def overlap_time(tm1, dur, tm2):
    pdb.set_trace()

# Each Event gets one of these
class Event(object):
    def __repr__(self):
	return "Event(%s)" % (self.name,)

    def __init__(self, evid, name, begin, dur, rep):
................................................................................
	# Repetition-specific reason
	return self._applies(target)

# Daily repeat
class RepeatDaily(Repeat):

    def _applies(self, target):
	assert self.intvl == 1

	# This day or one within the counted range?
	days = (time.mktime(target) - self.base) / DAYSECS




	return int(days) < (self.count or 1)



# Weekly repeat
class RepeatWeekly(Repeat):

    def _applies(self, target):

	# Not right day of week
	basetm = self.basetm
	if self.basetm.tm_wday != target.tm_wday:
	    return False

	# This many weeks
	if self.count is not None:
	    t = self.base
	    for x in xrange(self.count):
		t2 = t + (x * WEEKSECS * self.intvl)
		t2tm = time.localtime(t2)
		if daymatch(t2tm, target):
		    return True
	    return False

	assert self.intvl == 1
	return True











# Monthly, by day of week
class RepeatMonthlyDay(Repeat):

    def init2(self, rep):
	# "2TU" means 2nd Tuesday of the month
	wday = rep[WER_WDAY].lower()
	dow = wday[-2:]
................................................................................
	mdiff = (12 + (target.tm_mday - basetm.tm_mday)) % 12
	return ((mdiff + 1) % self.intvl) == 0

# Yearly
class RepeatYearly(Repeat):
    def init2(self, rep):
	assert rep[WER_YDAY].lower() in DAYIDX
	assert self.intvl == 1

    def _applies(self, target):
	basetm = self.basetm
	return (target.tm_mon == basetm.tm_mon) and \
	    (target.tm_mday == basetm.tm_mday)

# Manually entered dates







|







 







<


|
>
>
>
>
|
>
>







<
|












|


>
>
>
>
>
>
>
>
>
>







 







|







140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
    if res:
	return res
    return cmp(tm1.tm_sec, tm2.tm_sec)

# Tell if tm2 overlaps at all with tm1's range
# (tm2 is assumed to lie at or later than tm1 due to pre-ordering.)
def overlap_time(tm1, dur, tm2):
    raise Exception, "overlap_time: TBD"

# Each Event gets one of these
class Event(object):
    def __repr__(self):
	return "Event(%s)" % (self.name,)

    def __init__(self, evid, name, begin, dur, rep):
................................................................................
	# Repetition-specific reason
	return self._applies(target)

# Daily repeat
class RepeatDaily(Repeat):

    def _applies(self, target):


	# This day or one within the counted range?
	days = int((time.mktime(target) - self.base) / DAYSECS)
	if self.intvl:
	    if (days % self.intvl):
		return False
	    days /= self.intvl
	if not self.count:
	    return True
	return (days < self.count)

# Weekly repeat
class RepeatWeekly(Repeat):

    def _applies(self, target):

	# Not right day of week

	if target.tm_wday not in self.days:
	    return False

	# This many weeks
	if self.count is not None:
	    t = self.base
	    for x in xrange(self.count):
		t2 = t + (x * WEEKSECS * self.intvl)
		t2tm = time.localtime(t2)
		if daymatch(t2tm, target):
		    return True
	    return False

	assert self.intvl == 1, "Interval 2"
	return True

    # We can get a list of days here
    def init2(self, rep):
	global DAYIDX

	if rep[WER_WDAY]:
	    self.days = frozenset(DAYIDX[s.lower()] for
		s in rep[WER_WDAY].split(','))
	else:
	    self.days = frozenset([self.basetm.tm_wday])

# Monthly, by day of week
class RepeatMonthlyDay(Repeat):

    def init2(self, rep):
	# "2TU" means 2nd Tuesday of the month
	wday = rep[WER_WDAY].lower()
	dow = wday[-2:]
................................................................................
	mdiff = (12 + (target.tm_mday - basetm.tm_mday)) % 12
	return ((mdiff + 1) % self.intvl) == 0

# Yearly
class RepeatYearly(Repeat):
    def init2(self, rep):
	assert rep[WER_YDAY].lower() in DAYIDX
	assert self.intvl == 1, "Interval 3"

    def _applies(self, target):
	basetm = self.basetm
	return (target.tm_mon == basetm.tm_mon) and \
	    (target.tm_mday == basetm.tm_mday)

# Manually entered dates