On Mon, 19 Mar 2012 14:45:51 -0700 (PDT), niph...@gmail.com said: > for every "period", duration is calculated as: > duration = db.periods.end_time.seconds() - > db.periods.start_time.seconds()
This is wrong. I reworked my data model so that the period start and stop fields were of type datetime. I then found the flaw in your logic above: the seconds() method returns the value of the seconds part of the datetime rather than the number of seconds of the duration. You can see this below. For one row (id==257), these are the values: <Row {'f_start': datetime.datetime(2012, 3, 25, 18, 18, 54), 'f_end': datetime.datetime(2012, 3, 25, 18, 19, 1)}> So, start at 18:18:54 today, stop at 18:19:01, so the duration should be 6 seconds. However: >>> duration = db.t_periods.f_end.seconds() - >>> db.t_periods.f_start.seconds() result = db(db.t_periods.id==257).select(db.t_periods.id,duration) >>> for r in result: ... print r ... <Row {'t_periods': <Row {'update_record': <function <lambda> at 0xa15e1b4>, 't_periods_archive': <gluon.dal.Set object at 0xa0dcf8c>, 0xa15e1b4>'id': 257, 'delete_record': <function <lambda> at 0xa15e10c>}>, 0xa15e1b4>'_extra': <Row {"(web2py_extract('second',t_periods.f_end) - 0xa15e1b4>web2py_extract('second',t_periods.f_start))": -53}>}> ...giving -53 seconds. In other words, it is the difference in the value of seconds rather than the duration. -- "You can have everything in life you want if you help enough other people get what they want" - Zig Ziglar. Who did you help today?