Rounding a time field to the nearest second?

I ran into an oddity in my program and was able to reproduce it in a simple test app here:
https://anvil.works/build#clone:I5GQL4DNMKMOUD2N=ZSOB6Q2ZXRJ2XCHQARWAYWEE

There’s a table with two time columns, ‘Time1’ and ‘Time2’. Upon clicking the “update” button, a server function runs:
now = datetime.datetime.utcnow()
ts_table = app_tables.time_stamps.search()
row = max(ts_table, key=lambda r: r[‘Time1’])
row[‘Time1’] = now
row[‘Time2’] = row[‘Time1’]

The result is that row[‘Time2’] is set to row[‘Time1’] rounded to the nearest second. (Verify by looking at the data table through the IDE.)

I can’t figure it out either. It is interesting that when you initially add the records, the precision is there. It is only when the Time2 column gets updated that the rounding happens. I have tried on Python 3 and using the row.update(Time1=now, Time2=maxval) methods, but still I get the same as you.

I’ll plug away for a bit longer.

Al

1 Like

This was a bug! Thanks for letting us know. It’s fixed now - if you run your test app again, you should find that it works.

2 Likes