any quick workaround for the datetime strftime() methods require year >= 1900

866 views
Skip to first unread message

vince

unread,
Feb 25, 2010, 11:47:13 PM2/25/10
to web2py-users
i run into some rare problem on web2py it's related to python's
limitation/bugs

Traceback (most recent call last):
File "/Library/WebServer/Documents/web2py/gluon/restricted.py", line
173, in restricted
exec ccode in environment
File "/Library/WebServer/Documents/web2py/applications/cychurch/
controllers/members.py", line 2523, in <module>
File "/Library/WebServer/Documents/web2py/gluon/globals.py", line
96, in <lambda>
self._caller = lambda f: f()
File "/Library/WebServer/Documents/web2py/applications/cychurch/
controllers/members.py", line 72, in show

form1=SQLFORM(db.members,thisrecord,fields=field1,deletable=False,showid=False,labels=header1,submit_button=T('Submit'))
File "/Library/WebServer/Documents/web2py/gluon/sqlhtml.py", line
656, in __init__
default = field.formatter(default)
File "/Library/WebServer/Documents/web2py/gluon/sql.py", line 2676,
in formatter
File "/Library/WebServer/Documents/web2py/gluon/validators.py", line
2214, in formatter
return self.other.formatter(value)
File "/Library/WebServer/Documents/web2py/gluon/validators.py", line
1960, in formatter
return value.strftime(self.format)
ValueError: year=1897 is before 1900; the datetime strftime() methods
require year >= 1900


is there any quick workaround for it? any ideas?

mdipierro

unread,
Feb 26, 2010, 12:09:16 AM2/26/10
to web2py-users
what about about we do something like this in web2py?

def format_date(d, format):
format = format.replace('%y',str(d.year)[-2:])
if d.year>=0:
format = format.replace('%Y',str(d.year))
else:
format = format.replace('%Y',str(d.year)+'B.C.')
d =
datetime.datetime(2000,d.month,d.day,d.hour,d.minute,d.second)
return d.strftime(format)

vince

unread,
Feb 26, 2010, 12:14:23 AM2/26/10
to web2py-users
is it just for years for B.C.? but currently python's strftime even
have error when it's year >= 1900.

mdipierro

unread,
Feb 26, 2010, 12:20:12 AM2/26/10
to web2py-users
No it work for every date but just B.C.

vince

unread,
Feb 26, 2010, 12:27:17 AM2/26/10
to web2py-users
it's just osx and windows problem since i've just google it. it's a
known problem on python.

ValueError: year=1897 is before 1900; the datetime strftime() methods
require year >= 1900

mdipierro

unread,
Feb 26, 2010, 12:32:37 AM2/26/10
to web2py-users
I tried. It does not work for year<=0 but works otherwise. It is now
in trunk. Nothing for you to do. Just upgrade and retry your code.
Should work.

On Feb 25, 11:14 pm, vince <lapcc...@gmail.com> wrote:

vince

unread,
Feb 26, 2010, 12:38:15 AM2/26/10
to web2py-users
ohoh! you are the man... that was quick! yes i tried and it just work!
Reply all
Reply to author
Forward
0 new messages