datetimes always have 1 hour offset when service is accessed from flash/flex, am I doing something wrong?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

datetimes always have 1 hour offset when service is accessed from flash/flex, am I doing something wrong?

Vasil Vangelovski
I have the following server code:

http://pastebin.com/f488161f0

When I call testService.getTime from a python client I get the correct time.

But when I use RemoteObject from flex like so:
http://pastebin.com/f48994af6

When the actual time is 11:30 I get 12:30 in the flex alert.

This same thing happens if I use a DjangoGateway (which is what I
actually need) either with pyamf 0.51 or the development version.

Am I doing something wrong?
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: datetimes always have 1 hour offset when service is accessed from flash/flex, am I doing something wrong?

Simon Bierbaum-2
That's probably a timezone issue - Python's datetime.datetime.now()  
gives you local time (i.e., the time in whatever timezone is set on  
the machine running the Python code), but the Flex Date()  
constructors excepts a number of seconds since the epoche in UTC.  
When Python serializes the date, it does not transmit timezone  
information. Try using datetime.datetime.utcnow() in Python.

Cheers, Simon

Am 02.02.2010 um 11:40 schrieb Vasil Vangelovski:

> I have the following server code:
>
> http://pastebin.com/f488161f0
>
> When I call testService.getTime from a python client I get the  
> correct time.
>
> But when I use RemoteObject from flex like so:
> http://pastebin.com/f48994af6
>
> When the actual time is 11:30 I get 12:30 in the flex alert.
>
> This same thing happens if I use a DjangoGateway (which is what I
> actually need) either with pyamf 0.51 or the development version.
>
> Am I doing something wrong?
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: datetimes always have 1 hour offset when service is accessed from flash/flex, am I doing something wrong?

Vasil Vangelovski
That makes sense, since I am in the CET timezone which is UTC+1 now.
Note that both the client and server are running on the same machine.

But how do I handle the DateTimeField values in my Django models. Do I
have to convert all the values to utc before I return them from my amf
methods?

When I was using DjangoAMF I didn't have any problems with the values
of DateTimeFields. With pyamf all the values are offset by one hour
when they reach the flash client.

On Tue, Feb 2, 2010 at 11:59 AM, Simon Bierbaum <[hidden email]> wrote:

> That's probably a timezone issue - Python's datetime.datetime.now() gives
> you local time (i.e., the time in whatever timezone is set on the machine
> running the Python code), but the Flex Date() constructors excepts a number
> of seconds since the epoche in UTC. When Python serializes the date, it does
> not transmit timezone information. Try using datetime.datetime.utcnow() in
> Python.
>
> Cheers, Simon
>
> Am 02.02.2010 um 11:40 schrieb Vasil Vangelovski:
>
>> I have the following server code:
>>
>> http://pastebin.com/f488161f0
>>
>> When I call testService.getTime from a python client I get the correct
>> time.
>>
>> But when I use RemoteObject from flex like so:
>> http://pastebin.com/f48994af6
>>
>> When the actual time is 11:30 I get 12:30 in the flex alert.
>>
>> This same thing happens if I use a DjangoGateway (which is what I
>> actually need) either with pyamf 0.51 or the development version.
>>
>> Am I doing something wrong?
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
>
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: datetimes always have 1 hour offset when service is accessed from flash/flex, am I doing something wrong?

Simon Bierbaum-2
Hm, I don't know much about Django, but after a bit of googleing it  
seems like Django does not store timezone information unless it's  
used with a PostgreSQL database which has a timezone-aware data type.  
DjangoAMF probably knows about this and converts all datetime objects  
to UTC before encoding them into AMF. PyAMF has no such magic. People  
on the web have made timezone-aware subclasses of DateTimeField, but  
it might be a lot of work for you to convert to that. IMHO, that  
would be the cleanest solution, being explicit about and  
standardizing the timezone your server uses and not rely on whatever  
the OS happens to use. Alternatively, I believe you can use  
pyamf.add_type() / remove_type() to override PyAMF's standard  
datetime handling, inject some code which does the timezone  
conversion and then calls the regular PyAMF code.

I hope I'm not being too confusing ;-)

Simon

Am 02.02.2010 um 12:11 schrieb Vasil Vangelovski:

> That makes sense, since I am in the CET timezone which is UTC+1 now.
> Note that both the client and server are running on the same machine.
>
> But how do I handle the DateTimeField values in my Django models. Do I
> have to convert all the values to utc before I return them from my amf
> methods?
>
> When I was using DjangoAMF I didn't have any problems with the values
> of DateTimeFields. With pyamf all the values are offset by one hour
> when they reach the flash client.
>
> On Tue, Feb 2, 2010 at 11:59 AM, Simon Bierbaum <[hidden email]>  
> wrote:
>> That's probably a timezone issue - Python's datetime.datetime.now
>> () gives
>> you local time (i.e., the time in whatever timezone is set on the  
>> machine
>> running the Python code), but the Flex Date() constructors excepts  
>> a number
>> of seconds since the epoche in UTC. When Python serializes the  
>> date, it does
>> not transmit timezone information. Try using  
>> datetime.datetime.utcnow() in
>> Python.
>>
>> Cheers, Simon
>>
>> Am 02.02.2010 um 11:40 schrieb Vasil Vangelovski:
>>
>>> I have the following server code:
>>>
>>> http://pastebin.com/f488161f0
>>>
>>> When I call testService.getTime from a python client I get the  
>>> correct
>>> time.
>>>
>>> But when I use RemoteObject from flex like so:
>>> http://pastebin.com/f48994af6
>>>
>>> When the actual time is 11:30 I get 12:30 in the flex alert.
>>>
>>> This same thing happens if I use a DjangoGateway (which is what I
>>> actually need) either with pyamf 0.51 or the development version.
>>>
>>> Am I doing something wrong?
>>> _______________________________________________
>>> PyAMF users mailing list - [hidden email]
>>> http://lists.pyamf.org/mailman/listinfo/users
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: datetimes always have 1 hour offset when service is accessed from flash/flex, am I doing something wrong?

Vasil Vangelovski
No, you're not being confusing.
Every django project has a TIME_ZONE setting which is used to set the
TZ env variable + it's used when the database backend is postgres to
store the datetimes as timestamp with timezone. But no matter what you
db backend is (in my case it's postgres) the values of DateTimeFields
will not have tzinfo. So what I'm doing right now is convert the
datetimes to utc considering the TIME_ZONE settings variable before I
send the response to the flash client which is not very clean but
works. I'm assuming DjangoAMF does it the same way. Having subclasses
of DateTimeField in all my models just to handle AMF (which is a very
small part of my project) is not optimal. pyamf.add_type() /
remove_type() is something I'll look into.

Thanks for the help.

On Tue, Feb 2, 2010 at 1:07 PM, Simon Bierbaum <[hidden email]> wrote:

> Hm, I don't know much about Django, but after a bit of googleing it seems
> like Django does not store timezone information unless it's used with a
> PostgreSQL database which has a timezone-aware data type. DjangoAMF probably
> knows about this and converts all datetime objects to UTC before encoding
> them into AMF. PyAMF has no such magic. People on the web have made
> timezone-aware subclasses of DateTimeField, but it might be a lot of work
> for you to convert to that. IMHO, that would be the cleanest solution, being
> explicit about and standardizing the timezone your server uses and not rely
> on whatever the OS happens to use. Alternatively, I believe you can use
> pyamf.add_type() / remove_type() to override PyAMF's standard datetime
> handling, inject some code which does the timezone conversion and then calls
> the regular PyAMF code.
>
> I hope I'm not being too confusing ;-)
>
> Simon
>
> Am 02.02.2010 um 12:11 schrieb Vasil Vangelovski:
>
>> That makes sense, since I am in the CET timezone which is UTC+1 now.
>> Note that both the client and server are running on the same machine.
>>
>> But how do I handle the DateTimeField values in my Django models. Do I
>> have to convert all the values to utc before I return them from my amf
>> methods?
>>
>> When I was using DjangoAMF I didn't have any problems with the values
>> of DateTimeFields. With pyamf all the values are offset by one hour
>> when they reach the flash client.
>>
>> On Tue, Feb 2, 2010 at 11:59 AM, Simon Bierbaum <[hidden email]> wrote:
>>>
>>> That's probably a timezone issue - Python's datetime.datetime.now() gives
>>> you local time (i.e., the time in whatever timezone is set on the machine
>>> running the Python code), but the Flex Date() constructors excepts a
>>> number
>>> of seconds since the epoche in UTC. When Python serializes the date, it
>>> does
>>> not transmit timezone information. Try using datetime.datetime.utcnow()
>>> in
>>> Python.
>>>
>>> Cheers, Simon
>>>
>>> Am 02.02.2010 um 11:40 schrieb Vasil Vangelovski:
>>>
>>>> I have the following server code:
>>>>
>>>> http://pastebin.com/f488161f0
>>>>
>>>> When I call testService.getTime from a python client I get the correct
>>>> time.
>>>>
>>>> But when I use RemoteObject from flex like so:
>>>> http://pastebin.com/f48994af6
>>>>
>>>> When the actual time is 11:30 I get 12:30 in the flex alert.
>>>>
>>>> This same thing happens if I use a DjangoGateway (which is what I
>>>> actually need) either with pyamf 0.51 or the development version.
>>>>
>>>> Am I doing something wrong?
>>>> _______________________________________________
>>>> PyAMF users mailing list - [hidden email]
>>>> http://lists.pyamf.org/mailman/listinfo/users
>>>
>>> _______________________________________________
>>> PyAMF users mailing list - [hidden email]
>>> http://lists.pyamf.org/mailman/listinfo/users
>>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
>
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: datetimes always have 1 hour offset when service is accessed from flash/flex, am I doing something wrong?

Nick Joyce
We added support for this issue in 0.5. Each Gateway class supports a timezone_offset kwarg which does offsetting calculation for you. In addition, DjangoGateway also supports settings.AMF_TIME_OFFSET (same as DjangoAMF afaik). You should be able to set that and everything 'just work' tm.

We did look at TIME_ZONE but we would also require pytz to convert that to the required offset.

Hope that goes some way to helping :)

Cheers,

Nick

On 2 Feb 2010, at 12:36, Vasil Vangelovski wrote:

> No, you're not being confusing.
> Every django project has a TIME_ZONE setting which is used to set the
> TZ env variable + it's used when the database backend is postgres to
> store the datetimes as timestamp with timezone. But no matter what you
> db backend is (in my case it's postgres) the values of DateTimeFields
> will not have tzinfo. So what I'm doing right now is convert the
> datetimes to utc considering the TIME_ZONE settings variable before I
> send the response to the flash client which is not very clean but
> works. I'm assuming DjangoAMF does it the same way. Having subclasses
> of DateTimeField in all my models just to handle AMF (which is a very
> small part of my project) is not optimal. pyamf.add_type() /
> remove_type() is something I'll look into.
>
> Thanks for the help.
>
> On Tue, Feb 2, 2010 at 1:07 PM, Simon Bierbaum <[hidden email]> wrote:
>> Hm, I don't know much about Django, but after a bit of googleing it seems
>> like Django does not store timezone information unless it's used with a
>> PostgreSQL database which has a timezone-aware data type. DjangoAMF probably
>> knows about this and converts all datetime objects to UTC before encoding
>> them into AMF. PyAMF has no such magic. People on the web have made
>> timezone-aware subclasses of DateTimeField, but it might be a lot of work
>> for you to convert to that. IMHO, that would be the cleanest solution, being
>> explicit about and standardizing the timezone your server uses and not rely
>> on whatever the OS happens to use. Alternatively, I believe you can use
>> pyamf.add_type() / remove_type() to override PyAMF's standard datetime
>> handling, inject some code which does the timezone conversion and then calls
>> the regular PyAMF code.
>>
>> I hope I'm not being too confusing ;-)
>>
>> Simon
>>
>> Am 02.02.2010 um 12:11 schrieb Vasil Vangelovski:
>>
>>> That makes sense, since I am in the CET timezone which is UTC+1 now.
>>> Note that both the client and server are running on the same machine.
>>>
>>> But how do I handle the DateTimeField values in my Django models. Do I
>>> have to convert all the values to utc before I return them from my amf
>>> methods?
>>>
>>> When I was using DjangoAMF I didn't have any problems with the values
>>> of DateTimeFields. With pyamf all the values are offset by one hour
>>> when they reach the flash client.
>>>
>>> On Tue, Feb 2, 2010 at 11:59 AM, Simon Bierbaum <[hidden email]> wrote:
>>>>
>>>> That's probably a timezone issue - Python's datetime.datetime.now() gives
>>>> you local time (i.e., the time in whatever timezone is set on the machine
>>>> running the Python code), but the Flex Date() constructors excepts a
>>>> number
>>>> of seconds since the epoche in UTC. When Python serializes the date, it
>>>> does
>>>> not transmit timezone information. Try using datetime.datetime.utcnow()
>>>> in
>>>> Python.
>>>>
>>>> Cheers, Simon
>>>>
>>>> Am 02.02.2010 um 11:40 schrieb Vasil Vangelovski:
>>>>
>>>>> I have the following server code:
>>>>>
>>>>> http://pastebin.com/f488161f0
>>>>>
>>>>> When I call testService.getTime from a python client I get the correct
>>>>> time.
>>>>>
>>>>> But when I use RemoteObject from flex like so:
>>>>> http://pastebin.com/f48994af6
>>>>>
>>>>> When the actual time is 11:30 I get 12:30 in the flex alert.
>>>>>
>>>>> This same thing happens if I use a DjangoGateway (which is what I
>>>>> actually need) either with pyamf 0.51 or the development version.
>>>>>
>>>>> Am I doing something wrong?
>>>>> _______________________________________________
>>>>> PyAMF users mailing list - [hidden email]
>>>>> http://lists.pyamf.org/mailman/listinfo/users
>>>>
>>>> _______________________________________________
>>>> PyAMF users mailing list - [hidden email]
>>>> http://lists.pyamf.org/mailman/listinfo/users
>>>>
>>> _______________________________________________
>>> PyAMF users mailing list - [hidden email]
>>> http://lists.pyamf.org/mailman/listinfo/users
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: datetimes always have 1 hour offset when service is accessed from flash/flex, am I doing something wrong?

Vasil Vangelovski
Yes, I tried this. The problem is that when I pass timezone_offset =
3600 (or other value <> 0) or set AMF_TIME_OFFSET return values are
affected only when I access the amf service from the pyamf python
client, not when I access it from flash. Why is this so? And why is
there a note on settings.AMF_TIME_OFFSET and timezone_offset that says
it's only for legacy systems?
Assuming it would work, wouldn't a problem arise with daylight saving
time. Right now my timezone is UTC+1 but in summer it will be UTC+2.
If I instatiate the gateway with one hour offset now I'll have to
restart apache (or whichever webserver) in spring for the utc offset
to get recalculated.

On Tue, Feb 2, 2010 at 2:47 PM, Nick Joyce <[hidden email]> wrote:

> We added support for this issue in 0.5. Each Gateway class supports a timezone_offset kwarg which does offsetting calculation for you. In addition, DjangoGateway also supports settings.AMF_TIME_OFFSET (same as DjangoAMF afaik). You should be able to set that and everything 'just work' tm.
>
> We did look at TIME_ZONE but we would also require pytz to convert that to the required offset.
>
> Hope that goes some way to helping :)
>
> Cheers,
>
> Nick
>
> On 2 Feb 2010, at 12:36, Vasil Vangelovski wrote:
>
>> No, you're not being confusing.
>> Every django project has a TIME_ZONE setting which is used to set the
>> TZ env variable + it's used when the database backend is postgres to
>> store the datetimes as timestamp with timezone. But no matter what you
>> db backend is (in my case it's postgres) the values of DateTimeFields
>> will not have tzinfo. So what I'm doing right now is convert the
>> datetimes to utc considering the TIME_ZONE settings variable before I
>> send the response to the flash client which is not very clean but
>> works. I'm assuming DjangoAMF does it the same way. Having subclasses
>> of DateTimeField in all my models just to handle AMF (which is a very
>> small part of my project) is not optimal. pyamf.add_type() /
>> remove_type() is something I'll look into.
>>
>> Thanks for the help.
>>
>> On Tue, Feb 2, 2010 at 1:07 PM, Simon Bierbaum <[hidden email]> wrote:
>>> Hm, I don't know much about Django, but after a bit of googleing it seems
>>> like Django does not store timezone information unless it's used with a
>>> PostgreSQL database which has a timezone-aware data type. DjangoAMF probably
>>> knows about this and converts all datetime objects to UTC before encoding
>>> them into AMF. PyAMF has no such magic. People on the web have made
>>> timezone-aware subclasses of DateTimeField, but it might be a lot of work
>>> for you to convert to that. IMHO, that would be the cleanest solution, being
>>> explicit about and standardizing the timezone your server uses and not rely
>>> on whatever the OS happens to use. Alternatively, I believe you can use
>>> pyamf.add_type() / remove_type() to override PyAMF's standard datetime
>>> handling, inject some code which does the timezone conversion and then calls
>>> the regular PyAMF code.
>>>
>>> I hope I'm not being too confusing ;-)
>>>
>>> Simon
>>>
>>> Am 02.02.2010 um 12:11 schrieb Vasil Vangelovski:
>>>
>>>> That makes sense, since I am in the CET timezone which is UTC+1 now.
>>>> Note that both the client and server are running on the same machine.
>>>>
>>>> But how do I handle the DateTimeField values in my Django models. Do I
>>>> have to convert all the values to utc before I return them from my amf
>>>> methods?
>>>>
>>>> When I was using DjangoAMF I didn't have any problems with the values
>>>> of DateTimeFields. With pyamf all the values are offset by one hour
>>>> when they reach the flash client.
>>>>
>>>> On Tue, Feb 2, 2010 at 11:59 AM, Simon Bierbaum <[hidden email]> wrote:
>>>>>
>>>>> That's probably a timezone issue - Python's datetime.datetime.now() gives
>>>>> you local time (i.e., the time in whatever timezone is set on the machine
>>>>> running the Python code), but the Flex Date() constructors excepts a
>>>>> number
>>>>> of seconds since the epoche in UTC. When Python serializes the date, it
>>>>> does
>>>>> not transmit timezone information. Try using datetime.datetime.utcnow()
>>>>> in
>>>>> Python.
>>>>>
>>>>> Cheers, Simon
>>>>>
>>>>> Am 02.02.2010 um 11:40 schrieb Vasil Vangelovski:
>>>>>
>>>>>> I have the following server code:
>>>>>>
>>>>>> http://pastebin.com/f488161f0
>>>>>>
>>>>>> When I call testService.getTime from a python client I get the correct
>>>>>> time.
>>>>>>
>>>>>> But when I use RemoteObject from flex like so:
>>>>>> http://pastebin.com/f48994af6
>>>>>>
>>>>>> When the actual time is 11:30 I get 12:30 in the flex alert.
>>>>>>
>>>>>> This same thing happens if I use a DjangoGateway (which is what I
>>>>>> actually need) either with pyamf 0.51 or the development version.
>>>>>>
>>>>>> Am I doing something wrong?
>>>>>> _______________________________________________
>>>>>> PyAMF users mailing list - [hidden email]
>>>>>> http://lists.pyamf.org/mailman/listinfo/users
>>>>>
>>>>> _______________________________________________
>>>>> PyAMF users mailing list - [hidden email]
>>>>> http://lists.pyamf.org/mailman/listinfo/users
>>>>>
>>>> _______________________________________________
>>>> PyAMF users mailing list - [hidden email]
>>>> http://lists.pyamf.org/mailman/listinfo/users
>>>
>>> _______________________________________________
>>> PyAMF users mailing list - [hidden email]
>>> http://lists.pyamf.org/mailman/listinfo/users
>>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
>
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users