Commit 64e97fca authored by Jérome Perrin's avatar Jérome Perrin

Support timezone conversion on date fields

parent 08151a03
......@@ -1346,6 +1346,11 @@ class DateTimeWidget(Widget):
description=("Display timezone"),
default=0)
default_timezone = fields.StringField('default_timezone',
title="Default timezone",
description=("Convert dates to the given timezone"),
default='')
default = fields.DateTimeField('default',
title="Default",
description=("The default datetime."),
......@@ -1453,6 +1458,7 @@ class DateTimeWidget(Widget):
This only describes the field format settings, not the actual
format of provided value.
query : Passthrough of given value.
timezone: the timezone to consider.
"""
if not value:
return None
......@@ -1463,11 +1469,17 @@ class DateTimeWidget(Widget):
value = value.encode(field.get_form_encoding())
return {'query': value,
'format': field.get_value('date_separator').join(input_order),
'timezone': field.get_value('default_timezone'),
'type': 'date'}
def render(self, field, key, value, REQUEST, render_prefix=None):
use_ampm = field.get_value('ampm_time_style')
use_timezone = field.get_value('timezone_style')
timezone = field.get_value('default_timezone')
# FIXME: backwards compatibility hack:
if not hasattr(field, 'sub_form'):
from StandardFields import create_datetime_text_sub_form
field.sub_form = create_datetime_text_sub_form(field)
# Is it still usefull to test the None value,
# as DateTimeField should be considerer as the other field
......@@ -1486,6 +1498,8 @@ class DateTimeWidget(Widget):
ampm = None
timezone = field.get_value("default_timezone")
if isinstance(value, DateTime):
if timezone:
value = value.toZone(timezone)
year = "%04d" % value.year()
month = "%02d" % value.month()
day = "%02d" % value.day()
......@@ -1550,6 +1564,9 @@ class DateTimeWidget(Widget):
use_ampm = field.get_value('ampm_time_style')
use_timezone = field.get_value('timezone_style')
default_timezone = field.get_value('default_timezone')
if default_timezone:
value = value.toZone(default_timezone)
year = "%04d" % value.year()
month = "%02d" % value.month()
......
......@@ -58,7 +58,10 @@ def castDate(value, change_timezone=True):
# input.
assert value['type'] == 'date'
format = value.get('format')
timezone = value.get('timezone')
value = value['query']
if timezone:
value = "%s %s" % (value, timezone)
if format == '%m/%d/%Y':
date_kw.pop('datefmt')
if isinstance(value, DateTime):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment