1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2006-2008 CollabNet. All rights reserved.
6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms
8 # are also available at http://subversion.tigris.org/license-1.html.
9 # If newer versions of this license are posted there, you may use a
10 # newer version instead, at your option.
12 # This software consists of voluntary contributions made by many
13 # individuals. For exact contribution history, see the revision
14 # history and logs, available at http://cvs2svn.tigris.org/.
15 # ====================================================================
17 """This module contains a class to manage time ranges."""
20 class TimeRange(object):
21 __slots__
= ('t_min', 't_max')
24 # Start out with a t_min higher than any incoming time T, and a
25 # t_max lower than any incoming T. This way the first T will push
26 # t_min down to T, and t_max up to T, naturally (without any
27 # special-casing), and successive times will then ratchet them
28 # outward as appropriate.
32 def add(self
, timestamp
):
33 """Expand the range to encompass TIMESTAMP."""
35 if timestamp
< self
.t_min
:
36 self
.t_min
= timestamp
37 if timestamp
> self
.t_max
:
38 self
.t_max
= timestamp
40 def __cmp__(self
, other
):
41 # Sorted by t_max, and break ties using t_min.
42 return cmp(self
.t_max
, other
.t_max
) or cmp(self
.t_min
, other
.t_min
)
44 def __lt__(self
, other
):
45 c
= cmp(self
.t_max
, other
.t_max
)
47 return self
.t_min
< other
.t_min