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.selectors import yes, require_group_compat |
14 from cubicweb.selectors import yes, require_group_compat |
15 from cubicweb.appobject import AppObject |
15 from cubicweb.appobject import AppObject |
122 elif etype == 'Time': |
122 elif etype == 'Time': |
123 format = self.req.property_value('ui.time-format') |
123 format = self.req.property_value('ui.time-format') |
124 try: |
124 try: |
125 # (adim) I can't find a way to parse a Time with a custom format |
125 # (adim) I can't find a way to parse a Time with a custom format |
126 date = strptime(value, format) # this returns a DateTime |
126 date = strptime(value, format) # this returns a DateTime |
127 return timedelta(0, date.hour *60*60 + date.minute*60 + date.second, 0) |
127 return datetime.timedelta(0, date.hour *60*60 + date.minute*60 + date.second, 0) |
128 except: |
128 except: |
129 raise ValueError('can\'t parse %r (expected %s)' % (value, format)) |
129 raise ValueError('can\'t parse %r (expected %s)' % (value, format)) |
130 try: |
130 try: |
131 format = self.req.property_value('ui.date-format') |
131 format = self.req.property_value('ui.date-format') |
132 return strptime(value, format) |
132 dt = strptime(value, format) |
|
133 return datetime.date(dt.year, dt.month, dt.day) |
133 except: |
134 except: |
134 raise ValueError('can\'t parse %r (expected %s)' % (value, format)) |
135 raise ValueError('can\'t parse %r (expected %s)' % (value, format)) |
135 |
136 |
136 |
137 |
137 def notify_edited(self, entity): |
138 def notify_edited(self, entity): |