myPIM

Check-in [8e93c40401]
Login

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

Overview
Comment:Add intervals
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:8e93c40401fd08dedb5f70f5a1c3dade59a2650303fe431bf3ee2c62e6d297a6
User & Date: ajv-899-334-8894@vsta.org 2009-11-01 19:54:08
Context
2011-10-28
21:57
*** empty log message *** check-in: e4515f536c user: ajv-899-334-8894@vsta.org tags: master, trunk
2009-11-01
19:54
Add intervals check-in: 8e93c40401 user: ajv-899-334-8894@vsta.org tags: master, trunk
2009-10-29
20:05
It's easier to see the day of the week for each date check-in: c985632d35 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pimtime.py.

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
150
151
152
153
154
155
156









































































































































157
158
159
160
161
162
163
    def __str__(self):
	t = self.start
	if self.time <> None:
	    return "%s %02d:%02d" % (str(self.start), \
		self.time[0], self.time[1])
	return str(self.start)

    # Tell if the event is in the future of the given date
    def isFuture(self, date):
	e = self.start
	if date.y < e.y:
	    return True

	if date.y > e.y:
	    return False

	if date.m < e.m:
	    return True

	if date.m > e.m:
	    return False

	return date.d < e.d

    # Tell if the event is in the past of the given date
    # A little more complicated than future, due to repeating
    #  events.
    def isPast(self, date):
	# Think about repeated events
	if self.rept <> None:
	    # If repeats endlessly, can't be past.  Otherwise
	    #  use end date/time for checking.
	    e = self.end
	    if e == None:
		return False
	else:
	    e = self.start

	# Compare years
	if e.y > date.y:
	    return False
	if e.y < date.y:
	    return True

	# Years match, now compare months
	if e.m > date.m:
	    return False
	if e.m < date.m:
	    return True

	# Months match, get answer from day
	return e.d < date.d

    # Tell if the given "tm" is a match on this Event
    #  to the granularity of date (i.e., not hour or minute)
    def dayHit(self, date):
	# Check if event is a future or past event
	if self.isFuture(date) or self.isPast(date):
	    return False

	# One time events must match date
	e = self.start
	if self.rept == None:
................................................................................
	    return e.d == date.d

	# Yearly on nth day of week in this month
	assert self.rept == 7
	if e.weekday() <> date.weekday():
	    return False
	return (e.d / 7) == (date.d / 7)










































































































































    # Return string for day/month/year of start time
    def mdy(self):
	return str(self.start)

    # Set the repeat qualifier for this Event
    # Format is:







|

|
<
<

<
<
<
<
<
<
<
<
<
<
<
|













|
<
|
<
<
<
<
<
<
<
<
<
<
<



|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







45
46
47
48
49
50
51
52
53
54


55











56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71











72
73
74
75
76
77
78
79
80
81
82
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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
    def __str__(self):
	t = self.start
	if self.time <> None:
	    return "%s %02d:%02d" % (str(self.start), \
		self.time[0], self.time[1])
	return str(self.start)

    # Tell if self.start is in the future of the given date
    def isFuture(self, date):
	return date < self.start














    # Tell if self's event is in the past of the given date
    # A little more complicated than future, due to repeating
    #  events.
    def isPast(self, date):
	# Think about repeated events
	if self.rept <> None:
	    # If repeats endlessly, can't be past.  Otherwise
	    #  use end date/time for checking.
	    e = self.end
	    if e == None:
		return False
	else:
	    e = self.start

	# Compare dates

	return e < date












    # Tell if the given "tm" is a match on this Event
    #  to the granularity of date (i.e., not hour or minute)
    def dayHit1(self, date):
	# Check if event is a future or past event
	if self.isFuture(date) or self.isPast(date):
	    return False

	# One time events must match date
	e = self.start
	if self.rept == None:
................................................................................
	    return e.d == date.d

	# Yearly on nth day of week in this month
	assert self.rept == 7
	if e.weekday() <> date.weekday():
	    return False
	return (e.d / 7) == (date.d / 7)

    # Tell how many times our event occurs from its start until
    #  reaching the "date".
    # Our count is number of *repetitions*, so if the event has
    #  a starting date, and then happens two more times, we return 2.
    def countEvents(self, date):
	nevent = 0
	t = self.start
	while t <> date:
	    # Make sure we didn't somehow skip over our target
	    assert t < date

	    # Daily
	    if self.rept == 0:
		t = xcal.gdate(t.ndaysg() + 1)

	    # Weekdays
	    elif self.rept == 1:
		raise Exception, "Interval on weekdays"

	    # Weekly on this day of the week
	    elif self.rept == 2:
		t = xcal.gdate(t.ndaysg() + 7)

	    # Monthly on this day of the month
	    elif self.rept == 3:
		year = t.y
		mnth = t.m
		if mnth < 12:
		    mnth += 1
		else:
		    mnth = 1
		    year += 1
		t = xcal.Date(year, mnth, t.d)

	    # Monthly on nth day of this week in the month
	    elif self.rept == 4:
		# Week #, zero-based, and day in
		#  that week index.
		week = (t.d - 1) / 7
		day = t.weekday()

		# Bump to new month
		year = t.y
		mnth = t.m
		if mnth < 12:
		    mnth += 1
		else:
		    mnth = 1
		    year += 1

		# Get first day of this month for the week'th week
		t = xcal.Date(year, mnth, 1 + week*7)

		# Figure out how many days into this week we need
		#  to go to get our day of the week.
		tday = t.weekday()
		if tday >= day:
		    d = t.d + (tday - day)
		else:
		    d = t.d + (7 + (tday - day))

		# Move to this Date
		t = xcal.Date(t.y, t.m, d)

	    # Yearly on nth day of this week of this month,
	    #  counting backwards
	    elif self.rept == 5:
		week = (t.days2next() - 1) / 7
		tday = t.weekday()

		# Bump to first day of new month
		year = t.y
		mnth = t.m
		if mnth < 12:
		    mnth += 1
		else:
		    mnth = 1
		    year += 1
		t = xcal.Date(year, mnth, 1)

		# Bump to first day of target week
		t = xcal.Date(year, mnth, t.days2next() - 7*week)

		# And move to day of week in this week
		tday = t.weekday()
		if tday > day:
		    d = t.d + (tday - day)
		else:
		    d = t.d + (7 + (tday - day))
		t = xcal.Date(t.y, t.m, d)

	    # Yearly on this date
	    elif self.rept == 6:
		t = xcal.Date(t.y+1, t.m, t.d)

	    # Yearly on nth day of this week of this month
	    else:
		assert self.rept == 7

		# Week #, zero-based, and day in
		#  that week index.
		week = (t.d - 1) / 7
		day = t.weekday()

		# Get first day of this month for the week'th week
		t = xcal.Date(t.y+1, t.m, 1 + week*7)

		# Figure out how many days into this week we need
		#  to go to get our day of the week.
		tday = t.weekday()
		if tday >= day:
		    d = t.d + (tday - day)
		else:
		    d = t.d + (7 + (tday - day))

		# Move to this Date
		t = xcal.Date(t.y, t.m, d)

	    # Bump count of repetitions
	    nevent += 1

	return nevent

    # Wrapper around dayHit1().
    # dayHit1() tells us if the given date matches our event.
    # If there is no "nth" qualifier, that is the answer.  If there
    #  is an "every <nth>" qualifier, we then need to see if the
    #  interval also matches.
    def dayHit(self, date):
	res = self.dayHit1(date)
	if not res:
	    return False
	if not self.nth:
	    return True
	nevents = self.countEvents(date)
	return (nevents % self.nth) == 0

    # Return string for day/month/year of start time
    def mdy(self):
	return str(self.start)

    # Set the repeat qualifier for this Event
    # Format is: