[Zope3-dev] Re: SVN: Zope3/branches/3.3/ Fixed issue 525:
DateWidget ru-format
Gary Poster
gary at zope.com
Mon Jun 26 17:58:35 EDT 2006
On Jun 26, 2006, at 5:12 PM, Tres Seaver wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dmitry Vasiliev wrote:
>> Benji York wrote:
...
>>>> Why does the display of the default DateTime widget change?
>>
>> DatetimeWidget now use zope.i18n for parse and format values so the
>> display is the same as for DatetimeDisplayWidget (note the line
>> 1529 of
>> the form.txt).
>>
>>> ...and in such a strange way?
>>
>> It's the datetime format for the default locale, see the
>> specification
>> in zope/i18n/locales/data/root.xml.
>>
>
> That breaks a test:
>
> File
> "/home/tseaver/projects/Zope-CVS/tseaver-retire_zpkg-2.10/lib/
> python/zope/formlib/form.txt",
> line 1547, in form.txt
> Failed example:
> print MyAddForm(None, request)() # doctest: +NORMALIZE_WHITESPACE
> Expected:
> <input class="textType" id="form.identifier"
> name="form.identifier"
> size="10" type="text" value="" />
> <input class="textType" id="form.name" name="form.name" size="20"
> type="text" value="" />
> <input class="textType" id="form.min_size" name="form.min_size"
> size="10" type="text" value="" />
> <input class="textType" id="form.max_size" name="form.max_size"
> size="10" type="text" value="" />
> <input class="textType" id="form.now" name="form.now" size="20"
> type="text" value="2002-12-02 12:30:00" />
> Got:
> <input class="textType" id="form.identifier"
> name="form.identifier"
> size="10" type="text" value="" />
> <input class="textType" id="form.name" name="form.name" size="20"
> type="text" value="" />
> <input class="textType" id="form.min_size" name="form.min_size"
> size="10" type="text" value="" />
> <input class="textType" id="form.max_size" name="form.max_size"
> size="10" type="text" value="" />
> <input class="textType" id="form.now" name="form.now" size="20"
> type="text" value="2002 12 2 12:30:00 " />
>
>
> not onlyt that, but I don't believe that '2002 12 2 12:30:00' is a
> valid date representation in *any* standard locale. The
> dashes-with-leading-zeros should be the default (it is the stock ISO
> date format).
Well, it's worse than that, for tests: if you are filling out forms
in a default locale (as you'll get without specifying one, or with
the test language), then you need to use the format shown in the test
above--and you *must* fill out the date with two spaces between the
date and time, seconds showing, *and* a subsequent space. For
instance, what you wrote ('2002 12 2 12:30:00') would not be parsed:
it needs to be '2002 12 2 12:30:00 ' (note last space).
As Stephan said in his reply, this is not anyone's fault in the Zope
community: it's what is specified in the ICU XML files in zope/i18n/
locales/data (specifically root.xml).
However, I'm not sure the new widget behavior is great for non-
default locales either. Certainly being able to display dates in a
locale-specific way is nice, but the input seems to be problematic.
If you specify an ACCEPT-LANGUAGE of "en-US", for instance, you need
to fill in "Dec 2, 2002 12:30:00 PM", if I remember correctly. Fully
spelling out "December" does not work. Leaving off the seconds
doesn't work. Any other format will not work. I didn't check, but
assume other languages result in similar restrictions in input.
The data in en.xml could be usable to get a more robust approach, and
it could even be done without change to zope.i18n for dates. But
AFAICT, for datetimes some help would need to be implemented in the
i18n.locale module (since the order of dates and times is specified
in the XML); and for datetimes and times I think we'd want to make
specifying seconds, and maybe even minutes, optional. This is
probably doable, but it seems like it might be painful to code and test.
I understand what Dmitry did, and why he did it. It makes sense
theoretically, but seems to fall down a bit practically. I wonder if
this should be an optional set of date and datetime widgets, rather
than the default ones. I think I've heard that the parsing in the
old datetime widget was Ameri-centric, but at least it could handle
an ISO standard that was unambiguous, defensible, and easily
described in some static "how to specify a date" example or
instructions.
The other approach is for someone to spend some time polishing the
i18n.locale formatting code a bit. That won't solve the test problem
('2005 4 12 12:15:00 ') but it would at least make the primary user
experience more reasonable.
(I made zc.datetimewidget just default to the old behavior, because
the JS needs to have a workable definition of how to render dates,
and specifying ISO is nice and simple.)
Gary
More information about the Zope3-dev
mailing list