fix: fix timezone edge case for WuttaDateWidget
This commit is contained in:
parent
590441c0be
commit
7cfe6e15f4
2 changed files with 11 additions and 3 deletions
|
|
@ -234,6 +234,9 @@ class WuttaDateWidget(DateInputWidget):
|
|||
""" """
|
||||
readonly = kw.get("readonly", self.readonly)
|
||||
if readonly and cstruct:
|
||||
try:
|
||||
dt = datetime.date.fromisoformat(cstruct)
|
||||
except ValueError:
|
||||
dt = datetime.datetime.fromisoformat(cstruct)
|
||||
return self.app.render_date(dt)
|
||||
|
||||
|
|
|
|||
|
|
@ -139,6 +139,9 @@ class TestWuttaDateWidget(WebTestCase):
|
|||
return mod.WuttaDateWidget(self.request, **kwargs)
|
||||
|
||||
def test_serialize(self):
|
||||
self.config.setdefault("wuttatest.timezone.default", "America/Los_Angeles")
|
||||
tzlocal = get_timezone_by_name("America/Los_Angeles")
|
||||
|
||||
node = colander.SchemaNode(colander.Date())
|
||||
field = self.make_field(node)
|
||||
|
||||
|
|
@ -156,7 +159,9 @@ class TestWuttaDateWidget(WebTestCase):
|
|||
|
||||
# now try again with datetime
|
||||
widget = self.make_widget()
|
||||
dt = datetime.datetime(2025, 1, 15, 8, 35)
|
||||
# nb. local zone is Los_Angeles but this is presumed to be "naive UTC"
|
||||
# hence local date is 2025-01-14
|
||||
dt = datetime.datetime(2025, 1, 15, 4, 35)
|
||||
|
||||
# editable widget has normal picker html
|
||||
result = widget.serialize(field, str(dt))
|
||||
|
|
@ -164,7 +169,7 @@ class TestWuttaDateWidget(WebTestCase):
|
|||
|
||||
# readonly is rendered per app convention
|
||||
result = widget.serialize(field, str(dt), readonly=True)
|
||||
self.assertEqual(result, "2025-01-15")
|
||||
self.assertEqual(result, "2025-01-14")
|
||||
|
||||
|
||||
class TestWuttaDateTimeWidget(WebTestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue