You could try the following (not tested!), which defines custom validators
for date and datetime that convert the date/time data entered by a user to
UTC, assuming the time offset is known. In the validator below, this offset
is session.tz_offset. the validator should convert the input datetime to
UTC, and convert back to the user's local time when displayed. The time
offset should ideally come from the user browser session.
usage is:
define_table('mytable',
..
Field('updated_on', 'datetime', requires=IS_DATETIME_UTC, ...),
)
code:
import time
class IS_DATETIME_UTC(object):
def __init__(self, format='%Y-%m-%d %H:%M:%S', error_message='invalid
datetime format - must be YYYY-MM-DD HH:MM:SS!'):
self.format = format
self.error_message = error_message
def __call__(self, value):
try:
y, m, d, hh, mm, ss, t0, t1, t2 = time.strptime(value,
str(self.format))
value = datetime.datetime(y, m, d, hh,mm)-session.tz_offset
#subtract offset here
return (value, None)
except:
return (value, self.error_message)
def formatter(self, value):
return (value+session.tz_offset).strftime('%Y-%m-%d %H:%M') #add
offset here
class IS_DATE_UTC(object):
def __init__(self, format='%Y-%m-%d', error_message='invalid date
format - must be YYYY-MM-DD!'):
self.format = format
self.error_message = error_message
def __call__(self, value):
try:
y, m, d, hh, mm, ss, t0, t1, t2 = time.strptime(value,
str(self.format))
value = (datetime.datetime(y, m, d,
hh,mm)-session.tz_offset).date() #subtract offset here
return (value, None)
except:
return (value, self.error_message)
def formatter(self, value):
return (value+session.tz_offset).strftime('%Y-%m-%d') #add offset
here
--