Allow Span display as Time or as Age

svn: r19939
This commit is contained in:
Doug Blank 2012-06-30 05:04:44 +00:00
parent 833dfcf7ef
commit e1247426da

View File

@ -92,7 +92,6 @@ class Span(object):
self.date2 = date2 self.date2 = date2
self.sort = (-9999, -9999) self.sort = (-9999, -9999)
self.minmax = (9999, -9999) self.minmax = (9999, -9999)
self.repr = None
self.precision = 2 self.precision = 2
self.negative = False self.negative = False
if self.valid: if self.valid:
@ -109,22 +108,18 @@ class Span(object):
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, 0) self.sort = (v, 0)
self.minmax = (v, v) self.minmax = (v, v)
#self.repr = self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.BEFORE) self.sort = (v, -Span.BEFORE)
self.minmax = (v - Span.BEFORE, v) self.minmax = (v - Span.BEFORE, v)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, Span.AFTER) self.sort = (v, Span.AFTER)
self.minmax = (v, v + Span.AFTER) self.minmax = (v, v + Span.AFTER)
#self.repr = "less than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "about " + self._format(self._diff(self.date1, self.date2))
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
start, stop = self.date2.get_start_stop_range() start, stop = self.date2.get_start_stop_range()
@ -134,89 +129,72 @@ class Span(object):
v2 = self.date1.sortval - start.sortval # max v2 = self.date1.sortval - start.sortval # max
self.sort = (v1, v2 - v1) self.sort = (v1, v2 - v1)
self.minmax = (v1, v2) self.minmax = (v1, v2)
#self.repr = ("between " + self._format(self._diff(self.date1, stop)) +
# " and " + self._format(self._diff(self.date1, start)))
elif self.date1.get_modifier() == Date.MOD_BEFORE: # BEFORE---------------------------- elif self.date1.get_modifier() == Date.MOD_BEFORE: # BEFORE----------------------------
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, 0) self.sort = (v, 0)
self.minmax = (0, v) self.minmax = (0, v)
#self.repr = "less than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.BEFORE) self.sort = (v, -Span.BEFORE)
self.minmax = (v, v + Span.BEFORE) self.minmax = (v, v + Span.BEFORE)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.AFTER) self.sort = (v, -Span.AFTER)
self.minmax = (0, v) self.minmax = (0, v)
#self.repr = "less than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "about " + self._format(self._diff(self.date1, self.date2))
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date1.get_modifier() == Date.MOD_AFTER: # AFTER---------------------------- elif self.date1.get_modifier() == Date.MOD_AFTER: # AFTER----------------------------
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, Span.AFTER) self.sort = (v, Span.AFTER)
self.minmax = (v, v + Span.AFTER) self.minmax = (v, v + Span.AFTER)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, Span.AFTER) self.sort = (v, Span.AFTER)
self.minmax = (v - Span.BEFORE, v + Span.AFTER) self.minmax = (v - Span.BEFORE, v + Span.AFTER)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, Span.AFTER) self.sort = (v, Span.AFTER)
self.minmax = (v, v + Span.AFTER) self.minmax = (v, v + Span.AFTER)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.AFTER) self.minmax = (v - Span.ABOUT, v + Span.AFTER)
#self.repr = "more than about " + self._format(self._diff(self.date1, self.date2))
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date1.get_modifier() == Date.MOD_ABOUT: # ABOUT---------------------------- elif self.date1.get_modifier() == Date.MOD_ABOUT: # ABOUT----------------------------
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "about " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.BEFORE) self.sort = (v, -Span.BEFORE)
self.minmax = (v - Span.BEFORE, v + Span.ABOUT) self.minmax = (v - Span.BEFORE, v + Span.ABOUT)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, Span.AFTER) self.sort = (v, Span.AFTER)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "less than about " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "about " + self._format(self._diff(self.date1, self.date2))
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "about " + self._format(self._diff(self.date1, self.date2))
elif (self.date1.get_modifier() == Date.MOD_RANGE or elif (self.date1.get_modifier() == Date.MOD_RANGE or
self.date1.get_modifier() == Date.MOD_SPAN): # SPAN---------------------------- self.date1.get_modifier() == Date.MOD_SPAN): # SPAN----------------------------
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
@ -227,23 +205,18 @@ class Span(object):
v2 = self.date2.sortval - stop.sortval # max v2 = self.date2.sortval - stop.sortval # max
self.sort = (v1, v2 - v1) self.sort = (v1, v2 - v1)
self.minmax = (v1, v2) self.minmax = (v1, v2)
#self.repr = ("between " + self._format(self._diff(start, self.date2)) +
# " and " + self._format(self._diff(stop, self.date2)))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, Span.BEFORE) self.sort = (v, Span.BEFORE)
self.minmax = (v - Span.BEFORE, v + Span.BEFORE) self.minmax = (v - Span.BEFORE, v + Span.BEFORE)
#self.repr = "more than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.AFTER) self.sort = (v, -Span.AFTER)
self.minmax = (v - Span.AFTER, v + Span.AFTER) self.minmax = (v - Span.AFTER, v + Span.AFTER)
#self.repr = "less than " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
v = self.date1.sortval - self.date2.sortval v = self.date1.sortval - self.date2.sortval
self.sort = (v, -Span.ABOUT) self.sort = (v, -Span.ABOUT)
self.minmax = (v - Span.ABOUT, v + Span.ABOUT) self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
#self.repr = "about " + self._format(self._diff(self.date1, self.date2))
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
start1, stop1 = self.date1.get_start_stop_range() start1, stop1 = self.date1.get_start_stop_range()
@ -256,8 +229,6 @@ class Span(object):
v2 = stop1.sortval - start2.sortval # max v2 = stop1.sortval - start2.sortval # max
self.sort = (v1, v2 - v1) self.sort = (v1, v2 - v1)
self.minmax = (v1, v2) self.minmax = (v1, v2)
#self.repr = ("between " + self._format(self._diff(start1, stop2)) +
# " and " + self._format(self._diff(stop1, start2)))
def is_valid(self): def is_valid(self):
return self.valid return self.valid
@ -290,154 +261,99 @@ class Span(object):
else: else:
return cmp(int(self), int(other)) return cmp(int(self), int(other))
def as_age(self):
"""
Get Span as an age (will not return more than Span.ALIVE).
"""
return self.get_repr(as_age=True)
def as_time(self):
"""
Get Span as a time (can be greater than Span.ALIVE).
"""
return self.get_repr(as_age=False)
def __repr__(self): def __repr__(self):
if self.repr is not None: """
return self.repr Get the Span as an age. Use Span.as_time() to get as a textual
elif self.valid: description of time greater than Span.ALIVE.
# TO_REWRITE: bug #5293 ! """
if self._diff(self.date1, self.date2)[0] > Span.ALIVE: return self.get_repr(as_age=True)
return _("less than %s years") % Span.ALIVE
if self.date1.get_modifier() == Date.MOD_NONE: def get_repr(self, as_age=False):
"""
Get the representation as a time or age.
"""
_repr = _("unknown")
if self.valid:
if as_age and self._diff(self.date1, self.date2)[0] > Span.ALIVE:
_repr = _("less than %s years") % Span.ALIVE
elif self.date1.get_modifier() == Date.MOD_NONE:
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
#v = self.date1.sortval - self.date2.sortval _repr = self._format(self._diff(self.date1, self.date2))
#self.sort = (v, 0)
#self.minmax = (v, v)
self.repr = self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
#v = self.date1.sortval - self.date2.sortval _repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, -Span.BEFORE)
#self.minmax = (v - Span.BEFORE, v)
self.repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
#v = self.date1.sortval - self.date2.sortval _repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, Span.AFTER)
#self.minmax = (v, v + Span.AFTER)
self.repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
#v = self.date1.sortval - self.date2.sortval _repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
# TO_FIX: bug #5293 !
self.repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
start, stop = self.date2.get_start_stop_range() start, stop = self.date2.get_start_stop_range()
start = Date(*start) start = Date(*start)
stop = Date(*stop) stop = Date(*stop)
#v1 = self.date1.sortval - stop.sortval # min _repr = (_("between") + " " + self._format(self._diff(self.date1, stop)) +
#v2 = self.date1.sortval - start.sortval # max
#self.sort = (v1, v2 - v1)
#self.minmax = (v1, v2)
self.repr = (_("between") + " " + self._format(self._diff(self.date1, stop)) +
" " + _("and") + " " + self._format(self._diff(self.date1, start))) " " + _("and") + " " + self._format(self._diff(self.date1, start)))
elif self.date1.get_modifier() == Date.MOD_BEFORE: # BEFORE---------------------------- elif self.date1.get_modifier() == Date.MOD_BEFORE: # BEFORE----------------------------
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
#v = self.date1.sortval - self.date2.sortval _repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, 0)
#self.minmax = (0, v)
self.repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
#v = self.date1.sortval - self.date2.sortval _repr = self._format((-1, -1 , -1))
#self.sort = (v, -Span.BEFORE)
#self.minmax = (v, v + Span.BEFORE)
self.repr = self._format((-1, -1 , -1))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
#v = self.date1.sortval - self.date2.sortval _repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, -Span.AFTER)
#self.minmax = (0, v)
self.repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
#v = self.date1.sortval - self.date2.sortval _repr = _("less than about") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
self.repr = _("less than about") + " " + self._format(self._diff(self.date1, self.date2))
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
#v = self.date1.sortval - self.date2.sortval _repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
self.repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date1.get_modifier() == Date.MOD_AFTER: # AFTER---------------------------- elif self.date1.get_modifier() == Date.MOD_AFTER: # AFTER----------------------------
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
#v = self.date1.sortval - self.date2.sortval _repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, Span.AFTER)
#self.minmax = (v, v + Span.AFTER)
self.repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
#v = self.date1.sortval - self.date2.sortval _repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, Span.AFTER)
#self.minmax = (v - Span.BEFORE, v + Span.AFTER)
self.repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
#v = self.date1.sortval - self.date2.sortval _repr = self._format((-1, -1 , -1))
#self.sort = (v, Span.AFTER)
#self.minmax = (v, v + Span.AFTER)
self.repr = self._format((-1, -1 , -1))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
#v = self.date1.sortval - self.date2.sortval _repr = _("more than about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.AFTER)
self.repr = _("more than about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
#v = self.date1.sortval - self.date2.sortval _repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
self.repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date1.get_modifier() == Date.MOD_ABOUT: # ABOUT---------------------------- elif self.date1.get_modifier() == Date.MOD_ABOUT: # ABOUT----------------------------
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
#v = self.date1.sortval - self.date2.sortval _repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
self.repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
#v = self.date1.sortval - self.date2.sortval _repr = _("more than about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
#self.sort = (v, -Span.BEFORE)
#self.minmax = (v - Span.BEFORE, v + Span.ABOUT)
self.repr = _("more than about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
#v = self.date1.sortval - self.date2.sortval _repr = _("less than about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
#self.sort = (v, Span.AFTER)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
self.repr = _("less than about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
#v = self.date1.sortval - self.date2.sortval _repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
self.repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
#v = self.date1.sortval - self.date2.sortval _repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
self.repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
elif (self.date1.get_modifier() == Date.MOD_RANGE or elif (self.date1.get_modifier() == Date.MOD_RANGE or
self.date1.get_modifier() == Date.MOD_SPAN): # SPAN---------------------------- self.date1.get_modifier() == Date.MOD_SPAN): # SPAN----------------------------
if self.date2.get_modifier() == Date.MOD_NONE: if self.date2.get_modifier() == Date.MOD_NONE:
start, stop = self.date1.get_start_stop_range() start, stop = self.date1.get_start_stop_range()
start = Date(*start) start = Date(*start)
stop = Date(*stop) stop = Date(*stop)
#v1 = self.date2.sortval - start.sortval # min _repr = (_("between") + " " + self._format(self._diff(start, self.date2)) +
#v2 = self.date2.sortval - stop.sortval # max
#self.sort = (v1, v2 - v1)
#self.minmax = (v1, v2)
self.repr = (_("between") + " " + self._format(self._diff(start, self.date2)) +
" " + _("and") + " " + self._format(self._diff(stop, self.date2))) " " + _("and") + " " + self._format(self._diff(stop, self.date2)))
elif self.date2.get_modifier() == Date.MOD_BEFORE: elif self.date2.get_modifier() == Date.MOD_BEFORE:
#v = self.date1.sortval - self.date2.sortval _repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, Span.BEFORE)
#self.minmax = (v - Span.BEFORE, v + Span.BEFORE)
self.repr = _("more than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_AFTER: elif self.date2.get_modifier() == Date.MOD_AFTER:
#v = self.date1.sortval - self.date2.sortval _repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
#self.sort = (v, -Span.AFTER)
#self.minmax = (v - Span.AFTER, v + Span.AFTER)
self.repr = _("less than") + " " + self._format(self._diff(self.date1, self.date2))
elif self.date2.get_modifier() == Date.MOD_ABOUT: elif self.date2.get_modifier() == Date.MOD_ABOUT:
#v = self.date1.sortval - self.date2.sortval _repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
#self.sort = (v, -Span.ABOUT)
#self.minmax = (v - Span.ABOUT, v + Span.ABOUT)
self.repr = _("age|about") + " " + self._format(self._diff(self.date1, self.date2)).format(precision=1)
elif (self.date2.get_modifier() == Date.MOD_RANGE or elif (self.date2.get_modifier() == Date.MOD_RANGE or
self.date2.get_modifier() == Date.MOD_SPAN): self.date2.get_modifier() == Date.MOD_SPAN):
start1, stop1 = self.date1.get_start_stop_range() start1, stop1 = self.date1.get_start_stop_range()
@ -446,15 +362,9 @@ class Span(object):
start2 = Date(*start2) start2 = Date(*start2)
stop1 = Date(*stop1) stop1 = Date(*stop1)
stop2 = Date(*stop2) stop2 = Date(*stop2)
#v1 = start1.sortval - stop2.sortval # min _repr = (_("between") + " " + self._format(self._diff(start1, stop2)) +
#v2 = stop1.sortval - start2.sortval # max
#self.sort = (v1, v2 - v1)
#self.minmax = (v1, v2)
self.repr = (_("between") + " " + self._format(self._diff(start1, stop2)) +
" " + _("and") + " " + self._format(self._diff(stop1, start2))) " " + _("and") + " " + self._format(self._diff(stop1, start2)))
return self.repr return _repr
else:
return _("unknown")
def __eq__(self, other): def __eq__(self, other):
""" """
@ -480,16 +390,15 @@ class Span(object):
return True return True
return int(self) > int(other) return int(self) > int(other)
def format(self, precision=2): def format(self, precision=2, as_age=True):
""" """
Force a string representation at a level of precision. Force a string representation at a level of precision.
1 = only most significant level (year, month, day) 1 = only most significant level (year, month, day)
2 = only most two significant levels (year, month, day) 2 = only most two significant levels (year, month, day)
3 = at most three items of signifance (year, month, day) 3 = at most three items of signifance (year, month, day)
""" """
self.repr = None
self.precision = precision self.precision = precision
return repr(self) return self.__repr__(self, as_age)
def _format(self, diff_tuple): def _format(self, diff_tuple):
if diff_tuple == (-1, -1, -1): return _("unknown") if diff_tuple == (-1, -1, -1): return _("unknown")