[facets] closes #1569459 (date-range facet with year < 1900)

use lgc.date.ustrftime() and lgc.date.ticks2datetime to convert js date ticks and have a chance to handle dates with year < 1900.

authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
changeset44775b275d45
branchstable
phasepublic
hiddenno
parent revision#dfd4680a23f0 [session] add find_entities and find_one_entity to session/request API (closes #1550045)
child revision#e094b3d4eb95 [server] move EditedEntity class to its own module, to avoid cyclic dependency when needed from e.g. session.py, #56ae3cd5f855 [packaging] prepare 3.11.2
files modified by this revision
web/facet.py
# HG changeset patch
# User Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
# Date 1301318637 -7200
# Mon Mar 28 15:23:57 2011 +0200
# Branch stable
# Node ID 44775b275d45a3b398ef6ffedcaabe9bc79c21db
# Parent dfd4680a23f00cdeb129f5d26e82058843253e86
[facets] closes #1569459 (date-range facet with year < 1900)

use lgc.date.ustrftime() and lgc.date.ticks2datetime to convert js date ticks and
have a chance to handle dates with year < 1900.

diff --git a/web/facet.py b/web/facet.py
@@ -51,11 +51,11 @@
1  from datetime import date, datetime, timedelta
2 
3  from logilab.mtconverter import xml_escape
4  from logilab.common.graph import has_path
5  from logilab.common.decorators import cached
6 -from logilab.common.date import datetime2ticks
7 +from logilab.common.date import datetime2ticks, ustrftime, ticks2datetime
8  from logilab.common.compat import all
9 
10  from rql import parse, nodes, utils
11 
12  from cubicweb import Unauthorized, typed_eid
@@ -979,11 +979,15 @@
13      def wdgclass(self):
14          return DateFacetRangeWidget
15 
16      def formatvalue(self, value):
17          """format `value` before in order to insert it in the RQL query"""
18 -        return '"%s"' % date.fromtimestamp(float(value) / 1000).strftime('%Y/%m/%d')
19 +        try:
20 +            date_value = ticks2datetime(float(value))
21 +        except (ValueError, OverflowError):
22 +            return u'"date out-of-range"'
23 +        return '"%s"' % ustrftime(date_value, '%Y/%m/%d')
24 
25 
26  class HasRelationFacet(AbstractFacet):
27      """This class simply filter according to the presence of a relation
28      (whatever the entity at the other end). It display a simple checkbox that