Hello Gary,

Sorry for the confusion, just managed it, the last one should fail.

    """this method normalizes datetime instances by converting them to
    utc, daylight saving times are also taken into account. This
    method requires an adapter to get the tzinfo from the request.
    
    >>> from zope import component, interface
    >>> import pytz
    >>> requestTZ = pytz.timezone('Europe/Vienna')
    >>> from zope.interface.common.idatetime import ITZInfo
    >>> from zope.publisher.interfaces.browser import IBrowserRequest
    >>> from zope.publisher.browser import TestRequest
    >>> @interface.implementer(ITZInfo)
    ... @component.adapter(IBrowserRequest)
    ... def tzinfo(request):
    ...     return requestTZ
    >>> component.provideAdapter(tzinfo)
    >>> dt = datetime.datetime(2006,5,1,12)
    >>> request = TestRequest()

    The Vienna timezone has a 2 hour offset to utc at this date.
    >>> normalize(request,dt)
    datetime.datetime(2006, 5, 1, 10, 0, tzinfo=<UTC>)

    At this date the timezone has only a one hour offset.
    >>> dt = datetime.datetime(2006,2,1,12)    
    >>> normalize(request,dt)
    datetime.datetime(2006, 2, 1, 11, 0, tzinfo=<UTC>)
    
    Normalizing UTC to UTC should work also
    >>> dt = datetime.datetime(2006,5,1,12,tzinfo=pytz.UTC)
    >>> normalize(request,dt)
    datetime.datetime(2006, 5, 1, 12, 0, tzinfo=<UTC>)
    
    This way too UTC to UTC
    >>> requestTZ = pytz.UTC
    >>> dt = datetime.datetime(2006,5,1,12)
    >>> normalize(request,dt)
    datetime.datetime(2006, 5, 1, 12, 0, tzinfo=<UTC>)
    """


Monday, July 17, 2006, 7:55:02 PM, you wrote:

GP> On Jul 17, 2006, at 12:53 PM, Adam Groszer wrote:

>> Hi there,
>>
>> Anybody tried to use the above?
>> For me it raises
>>
>>   Module zope.app.form.utility, line 348, in getWidgetsData
>>   Module zope.app.form.browser.widget, line 295, in getInputValue
>>   Module zc.datetimewidget.datetimewidget, line 123, in _toFieldValue
>>     res = normalizeDateTime(res, self.request)
>>   Module zc.datetimewidget.datetimewidget, line 48, in  
>> normalizeDateTime
>>     dt = zc.i18n.date.normalize(request, dt)
>>   Module zc.i18n.date, line 74, in normalize
>>     tzu = tzinfo.fromutc(dt).tzinfo
>> ValueError: fromutc: dt.tzinfo is not self
>>
>> Seems like that happens when in zc.i18n.date tzinfo == UTC
>>
>> def normalize(request, dt):
>>     if dt.tzinfo is None:
>>         tzinfo = ITZInfo(request)
>>     else:
>>         tzinfo = dt.tzinfo
>>
>>     tzu = tzinfo.fromutc(dt).tzinfo
>>
>> Anyway normalizing an UTC datetime to UTC is useless?!?!?
>> So if nobody goes against I'll correct that.

GP> Hi Adam.  I'm trying to follow, and having a bit of a hard time,  
GP> perhaps because I'm trying to work too quickly. :-)

GP> I thought you meant that the following test of zc.i18n.date.normalize
GP> would fail:

GP>      >>> dt = datetime.datetime(2006, 5, 1, 10, tzinfo=pytz.UTC)
GP>      >>> normalize(request, dt)
GP>      datetime.datetime(2006, 5, 1, 10, 0, tzinfo=<UTC>)

GP> However, I actually added this test to zc.i18n.date and it passed.  I
GP> checked it in (revision 69155), but I assume that means that I still  
GP> don't understand what the problem you identified is.  Could you maybe
GP> post a doctest that fails?

GP> Thanks

GP> Gary

-- 
Best regards,
 Groszer Adam
--
Quote of the day:
A thing moderately good is not so good as it ought to be. Moderation in temper 
is always a virtue; but moderation in principle is always a vice. 
- Thomas Paine 

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to