[Cubicweb] dealing with dates before 1900

Alexandre Fayolle alexandre.fayolle at logilab.fr
Fri Aug 20 22:39:10 CEST 2010


As part of a personal projects, I need to deal with date long before 1900 in   
a CW instance. Problem is, python's datetime module does not like this at all, 
and I get stack traces such as:

2010-08-20 22:30:56 - (cubicweb.web) ERROR: ValueError('year=1386 is before 
1900; the datetime strftime() methods require year >= 1900',)
Traceback (most recent call last):
  File "/home/alf/cubicweb/cubicweb/web/application.py", line 388, in 
main_publish
    result = controller.publish(rset=rset)
  File "/home/alf/cubicweb/cubicweb/web/views/basecontrollers.py", line 123, 
in publish
    rset=rset, view=view)
  File "/home/alf/cubicweb/cubicweb/cwvreg.py", line 378, in main_template
    res = obj.render(**kwargs)
  File "/home/alf/cubicweb/cubicweb/view.py", line 174, in render
    view_func(**context)
  File "/home/alf/cubicweb/cubicweb/web/views/basetemplates.py", line 141, in 
call
    view.render(w=w)
  File "/home/alf/cubicweb/cubicweb/view.py", line 174, in render
    view_func(**context)
  File "/home/alf/cubicweb/cubicweb/view.py", line 375, in call
    super(EntityView, self).call(**kwargs)
  File "/home/alf/cubicweb/cubicweb/view.py", line 213, in call
    self.wview(self.__regid__, rset, row=i, **kwargs)
  File "/home/alf/cubicweb/cubicweb/view.py", line 269, in wview
    self._cw.view(__vid, rset, __fallback_vid, w=self.w, **kwargs)
  File "/home/alf/cubicweb/cubicweb/req.py", line 314, in view
    return view.render(w=w, **kwargs)
  File "/home/alf/cubicweb/cubicweb/view.py", line 174, in render
    view_func(**context)
  File "/home/alf/cubicweb/cubicweb/web/views/primary.py", line 58, in 
cell_call
    self.render_entity(entity)
  File "/home/alf/cubicweb/cubicweb/web/views/primary.py", line 74, in 
render_entity
    self.render_entity_attributes(entity)
  File "/home/alf/cubicweb/cubicweb/web/views/primary.py", line 134, in 
render_entity_attributes
    initargs={'dispctrl': dispctrl})
  File "/home/alf/cubicweb/cubicweb/entity.py", line 480, in view
    return view.render(row=self.cw_row, col=self.cw_col, w=w, **kwargs)
  File "/home/alf/cubicweb/cubicweb/view.py", line 174, in render
    view_func(**context)
  File "/home/alf/cubicweb/cubicweb/web/views/reledit.py", line 89, in 
cell_call
    self._handle_attributes(entity, rschema, role, divid, reload, 
default_value)
  File "/home/alf/cubicweb/cubicweb/web/views/reledit.py", line 95, in 
_handle_attributes
    value = entity.printable_value(rtype)
  File "/home/alf/cubicweb/cubicweb/entity.py", line 578, in printable_value
    displaytime=displaytime)
  File "/home/alf/cubicweb/cubicweb/uilib.py", line 65, in printable_value
    return ustrftime(value, req.property_value('ui.date-format'))
  File "/home/alf/cubicweb/logilab/common/date.py", line 279, in ustrftime
    return unicode(somedate.strftime(str(fmt)), encoding)
ValueError: year=1386 is before 1900; the datetime strftime() methods require 
year >= 1900

Is there a recommended workaround for this? 

-- 
Alexandre Fayolle                              LOGILAB, Paris (France)
Formations Python, CubicWeb, Debian :  http://www.logilab.fr/formations
Développement logiciel sur mesure :      http://www.logilab.fr/services
Informatique scientifique:               http://www.logilab.fr/science



More information about the Cubicweb mailing list