Store dates in UTC format across all tables

52 views
Skip to first unread message

Gaurav Vichare

unread,
Jan 21, 2017, 7:26:02 AM1/21/17
to web2py-users
I want to store created_on and modified_on values of all tables in UTC format. Audit fields are added using db._common_fields.append(auth.signature) and  in auth.signature default value for created_on and modified_on is request.now, I want to change it to request.utcnow. So I tried following but its now working, it is still storing server time, not in UTC. 

auth.signature.created_on.default = request.utcnow
auth.signature.modified_on.default = request.utcnow
db._common_fields.append(auth.signature)


I am able to change default value to utc by explicitly defining it for each table like this

db.table_name.field_name.created_on.default =  request.utcnow
db.table_name.field_name.modified_on.default =  request.utcnow

But I don't want to repeat same thing for all tables.
So how can I override default values of modified_on and created_on with minimum lines of code?
My next task is to show record creation date/time according to user's timezone.

Thank You
- Gaurav Vichare

Dave S

unread,
Jan 23, 2017, 2:34:06 PM1/23/17
to web2py-users

On Saturday, January 21, 2017 at 4:26:02 AM UTC-8, Gaurav Vichare wrote:
I want to store created_on and modified_on values of all tables in UTC format. Audit fields are added using db._common_fields.append(auth.signature) and  in auth.signature default value for created_on and modified_on is request.now, I want to change it to request.utcnow

[...] 
So how can I override default values of modified_on and created_on with minimum lines of code?
My next task is to show record creation date/time according to user's timezone.

I don't have an answer to your main question,  but when you get to the user's timezone stuff, you may want to look at 

/dps
 

Leonel Câmara

unread,
Jan 25, 2017, 6:58:58 AM1/25/17
to web2py-users
this is the simplest way:

request.now = request.utcnow

Your way should also work if you do it after auth.define_tables() 
Reply all
Reply to author
Forward
0 new messages