Thanks for the heads-up!!  Switching over to datetime as we speak (and 
working pretty good!!!)

Best,
Julian

On Sunday, October 25, 2015 at 6:29:24 PM UTC-5, Anthony wrote:
>
> FYI, we're going to remove the timezone option from IS_DATE (which doesn't 
> work anyway), so you're better off using a datetime field and setting the 
> time to midnight.
>
> Anthony
>
> On Sunday, October 25, 2015 at 12:02:48 PM UTC-4, Julian Sanchez wrote:
>>
>> Thanks Anthony, great insight.
>>
>> Most data is user-generated so the intent is to imply midnight at the 
>> user's timezone, translate to UTC for storage, then apply the user's 
>> timezone when displaying/editing.  Can certainly switch to datetime field 
>> and zero out the time.
>>
>> Cheers,
>> Julian
>>
>> On Sunday, October 25, 2015 at 8:38:12 AM UTC-5, Anthony wrote:
>>>
>>> It appears to be a bug in the IS_DATE validator -- the code expects the 
>>> date object to have a tzinfo attribute, but only datetime and time objects 
>>> have that attribute.
>>>
>>> More generally, it is not clear how one should apply transformations to 
>>> dates based on timezones. If you know the date in UTC time, how can you 
>>> tell what the date should be in another timezone without knowing the 
>>> *time* in UTC as well? For example, if you have the date 2015-10-25 in 
>>> UTC, what is the date in the "America/Chicago" timezone? It would be 
>>> 2015-10-25 if the UTC time is after 5:00am, but 2015-10-24 if the UTC time 
>>> is before 5:00am. If you want to make such a transformation, you would have 
>>> to pick a particular time of day (either in the local timezone or UTC), 
>>> such as midnight -- but then you should probably be storing datetimes, not 
>>> simply dates.
>>>
>>> Anthony
>>>
>>> On Sunday, October 25, 2015 at 8:54:40 AM UTC-4, Julian Sanchez wrote:
>>>>
>>>> I'm developing an application that will have users from different time 
>>>> zones.  The intent is to store everything in UTC and translate to user's 
>>>> timezone at display/edit time.  I started working on my own solution when 
>>>> I 
>>>> came across this post 
>>>> <https://groups.google.com/forum/#!searchin/web2py/IS_DATE$20timezone/web2py/jIEUIb8wxtg/rWe5g-IhCwAJ>which
>>>>  
>>>> seems to indicate that if you specify a timezone parameter to the 
>>>> IS_DATE() 
>>>> validator web2py will do all the timezone translation for you.
>>>>
>>>> However every time I specify the timezone parameter to IS_DATE() I will 
>>>> get no dates validated no matter what
>>>>
>>>> Without specifying a timezone it obviously works:
>>>> def test_date():
>>>>     db.define_table('test_table',Field('usr_comment'),Field(
>>>> 'comment_date',requires=IS_DATE('%Y-%m-%d')))
>>>>     form =SQLFORM.grid(db.test_table, create=True,editable=True, 
>>>> user_signature=False)
>>>>     return dict(form=form)
>>>>
>>>>
>>>> However this:
>>>> def test_date():
>>>>     db.define_table('test_table', Field('usr_comment'), Field(
>>>> 'comment_date', requires=IS_DATE('%Y-%m-%d', timezone='America/Chicago'
>>>> )))
>>>>     form = SQLFORM.grid(db.test_table, create=True, editable=True, 
>>>> user_signature=False)
>>>>     return dict(form=form)
>>>>
>>>> or even this:
>>>> def test_date():
>>>>     from pytz import timezone
>>>>     mytz = timezone('America/Chicago')
>>>>     db.define_table('test_table', Field('usr_comment'),Field(
>>>> 'comment_date',requires=IS_DATE('%Y-%m-%d', timezone=mytz)))
>>>>     form=SQLFORM.grid(db.test_table, create=True, editable=True,
>>>> user_signature=False)
>>>>     return dict(form=form)
>>>>
>>>> Always tells me "Enter date as 1963-08-28" when submitting the form and 
>>>> never allows me to add/edit values (of course I'm entering dates as 
>>>> 2015-10-25). 
>>>>
>>>> Am I missing something or is there a bug with IS_DATE and timezone 
>>>> handling?
>>>>
>>>> Thanks,
>>>> Julian
>>>>
>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to