215
216
SPEC_TYPES.append(RevisionSpec_last)
219
class RevisionSpec_before(RevisionSpec):
223
def _match_on(self, branch, revs):
224
r = RevisionSpec(self.spec)._match_on(branch, revs)
225
if (r.revno is None) or (r.revno == 0):
227
return RevisionInfo(branch, r.revno - 1)
229
SPEC_TYPES.append(RevisionSpec_before)
218
232
class RevisionSpec_tag(RevisionSpec):
237
251
Spec for date revisions:
239
253
value can be 'yesterday', 'today', 'tomorrow' or a YYYY-MM-DD string.
240
it can also start with a '+/-/='. '+' says match the first
241
entry after the given date. '-' is match the first entry before the date
242
'=' is match the first entry after, but still on the given date.
244
+2005-05-12 says find the first matching entry after May 12th, 2005 at 0:00
245
-2005-05-12 says find the first matching entry before May 12th, 2005 at 0:00
246
=2005-05-12 says find the first match after May 12th, 2005 at 0:00 but before
247
May 13th, 2005 at 0:00
254
matches the first entry after a given date (either at midnight or
255
at a specified time).
249
257
So the proper way of saying 'give me all entries for today' is:
250
-r {date:+today}:{date:-tomorrow}
251
The default is '=' when not supplied
258
-r date:today..date:tomorrow
254
if self.spec[:1] in ('+', '-', '='):
255
match_style = self.spec[:1]
256
self.spec = self.spec[1:]
258
# XXX: this should probably be using datetime.date instead
259
today = datetime.datetime.today().replace(hour=0, minute=0, second=0,
260
today = datetime.datetime.fromordinal(datetime.date.today().toordinal())
261
261
if self.spec.lower() == 'yesterday':
262
262
dt = today - datetime.timedelta(days=1)
263
263
elif self.spec.lower() == 'today':
286
286
dt = datetime.datetime(year=year, month=month, day=day,
287
287
hour=hour, minute=minute, second=second)
291
if match_style == '-':
293
elif match_style == '=':
294
last = dt + datetime.timedelta(days=1)
297
for i in range(len(revs)-1, -1, -1):
298
r = branch.get_revision(revs[i])
299
# TODO: Handle timezone.
300
dt = datetime.datetime.fromtimestamp(r.timestamp)
301
if first >= dt and (last is None or dt >= last):
302
return RevisionInfo(branch, i+1,)
304
for i in range(len(revs)):
305
r = branch.get_revision(revs[i])
306
# TODO: Handle timezone.
307
dt = datetime.datetime.fromtimestamp(r.timestamp)
308
if first <= dt and (last is None or dt <= last):
309
return RevisionInfo(branch, i+1,)
289
for i in range(len(revs)):
290
r = branch.get_revision(revs[i])
291
# TODO: Handle timezone.
292
dt = datetime.datetime.fromtimestamp(r.timestamp)
294
return RevisionInfo(branch, i+1)
295
return RevisionInfo(branch, None)
311
297
SPEC_TYPES.append(RevisionSpec_date)