5 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
10 from datetime import timedelta |
10 import datetime |
11 |
11 |
12 from cubicweb import typed_eid |
12 from cubicweb import typed_eid |
13 from cubicweb.utils import strptime |
13 from cubicweb.utils import strptime |
14 from cubicweb.common.registerers import priority_registerer |
14 from cubicweb.common.registerers import priority_registerer |
15 from cubicweb.selectors import yes, require_group_compat |
15 from cubicweb.selectors import yes, require_group_compat |
124 elif etype == 'Time': |
124 elif etype == 'Time': |
125 format = self.req.property_value('ui.time-format') |
125 format = self.req.property_value('ui.time-format') |
126 try: |
126 try: |
127 # (adim) I can't find a way to parse a Time with a custom format |
127 # (adim) I can't find a way to parse a Time with a custom format |
128 date = strptime(value, format) # this returns a DateTime |
128 date = strptime(value, format) # this returns a DateTime |
129 return timedelta(0, date.hour *60*60 + date.minute*60 + date.second, 0) |
129 return datetime.timedelta(0, date.hour *60*60 + date.minute*60 + date.second, 0) |
130 except: |
130 except: |
131 raise ValueError('can\'t parse %r (expected %s)' % (value, format)) |
131 raise ValueError('can\'t parse %r (expected %s)' % (value, format)) |
132 try: |
132 try: |
133 format = self.req.property_value('ui.date-format') |
133 format = self.req.property_value('ui.date-format') |
134 return strptime(value, format) |
134 dt = strptime(value, format) |
|
135 return datetime.date(dt.year, dt.month, dt.day) |
135 except: |
136 except: |
136 raise ValueError('can\'t parse %r (expected %s)' % (value, format)) |
137 raise ValueError('can\'t parse %r (expected %s)' % (value, format)) |
137 |
138 |
138 |
139 |
139 def notify_edited(self, entity): |
140 def notify_edited(self, entity): |