[Openerp-community] time zone adjustment in MAKO files?

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

[Openerp-community] time zone adjustment in MAKO files?

DaleEMoore
I've used 

from dateutil import tz
from_zone
= tz.tzutc()
to_zone
= tz.tzlocal()
arrive
= arrive.replace(tzinfo=from_zone)
arrive_central
= arrive.astimezone(to_zone)

in hr_timesheet_invoice_create.py to output the correct local time but that isn't working for me in some MAKO reports.

Do you know how to get the correct local time out of a MAKO report?

I look forward to hearing from you,



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] time zone adjustment in MAKO files?

Ovnicraft



On Fri, May 10, 2013 at 7:32 AM, Dale E. Moore <[hidden email]> wrote:
I've used 


from dateutil import tz
from_zone
= tz.tzutc()
to_zone
= tz.tzlocal()
arrive
= arrive.replace(tzinfo=from_zone)
arrive_central
= arrive.astimezone(to_zone)
  
in hr_timesheet_invoice_create.py to output the correct local time but that isn't working for me in some MAKO reports.

Do you know how to get the correct local time out of a MAKO report?

Hello, AFAIK you always must compute in UTC, TZ comes from user preferences.

Regards, 

I look forward to hearing from you,



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp




--
Cristian Salamea
@ovnicraft

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] time zone adjustment in MAKO files?

DaleEMoore
Thanks for the feedback Cristian Salamea!

The user preferences are America/Chicago but what's being displayed/printed is UTC.


On Fri, May 10, 2013 at 8:05 AM, Ovnicraft <[hidden email]> wrote:



On Fri, May 10, 2013 at 7:32 AM, Dale E. Moore <[hidden email]> wrote:
I've used 


from dateutil import tz
from_zone
= tz.tzutc()
to_zone
= tz.tzlocal()
arrive
= arrive.replace(tzinfo=from_zone)
arrive_central
= arrive.astimezone(to_zone)
  
in hr_timesheet_invoice_create.py to output the correct local time but that isn't working for me in some MAKO reports.

Do you know how to get the correct local time out of a MAKO report?

Hello, AFAIK you always must compute in UTC, TZ comes from user preferences.

Regards, 

I look forward to hearing from you,



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp




--
Cristian Salamea
@ovnicraft


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] time zone adjustment in MAKO files?

DaleEMoore
Does anyone know how to calculate local time in a mako report? This

from dateutil import tz
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
arrive = arrive.replace(tzinfo=from_zone)
arrive_central = arrive.astimezone(to_zone)

is not working for me.



On Fri, May 10, 2013 at 8:30 AM, Dale E. Moore <[hidden email]> wrote:
Thanks for the feedback Cristian Salamea!

The user preferences are America/Chicago but what's being displayed/printed is UTC.


On Fri, May 10, 2013 at 8:05 AM, Ovnicraft <[hidden email]> wrote:



On Fri, May 10, 2013 at 7:32 AM, Dale E. Moore <[hidden email]> wrote:
I've used 


from dateutil import tz
from_zone
= tz.tzutc()
to_zone
= tz.tzlocal()
arrive
= arrive.replace(tzinfo=from_zone)
arrive_central
= arrive.astimezone(to_zone)
  
in hr_timesheet_invoice_create.py to output the correct local time but that isn't working for me in some MAKO reports.

Do you know how to get the correct local time out of a MAKO report?

Hello, AFAIK you always must compute in UTC, TZ comes from user preferences.

Regards, 

I look forward to hearing from you,



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp




--
Cristian Salamea
@ovnicraft



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] time zone adjustment in MAKO files?

Michael Telahun Makonnen
Simply replacing timezone data does not work. You have to *convert* from
one timezone to another.  But, because openerp doesn't attach timezone
to the time in the database there is an initial step required to add utc
timezone data. The general steps are:
1. Convert date/time from db into a naive datetime object
2. Attach utc timezone to get a timezone aware date/time object
3. Convert it to the timezone of your choice

In practice it looks like this:

from pytz import timezone
tzutc = timezone('UTC')
tzlocal = timezone('America/Chicago')
dt = datetime.strptime(myobject.time_field, '%Y-%m-%d %H:%M:%S')
utc_dt = tzutc.localize(dt, is_dst=False)
local_dt = utc_dt.astimezone(tzlocal)

Regards,
Mike.

On 05/10/2013 07:52 PM, Dale E. Moore wrote:

> Does anyone know how to calculate local time in a mako report? This
>
> |from dateutil import tz
> from_zone = tz.tzutc()
> to_zone = tz.tzlocal()
> arrive = arrive.replace(tzinfo=from_zone)
> arrive_central = arrive.astimezone(to_zone)|
>
>
> is not working for me.
>
>
>
> On Fri, May 10, 2013 at 8:30 AM, Dale E. Moore <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Thanks for the feedback Cristian Salamea!
>
>     The user preferences are America/Chicago but what's being
>     displayed/printed is UTC.
>
>
>     On Fri, May 10, 2013 at 8:05 AM, Ovnicraft <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>
>
>
>         On Fri, May 10, 2013 at 7:32 AM, Dale E. Moore
>         <[hidden email] <mailto:[hidden email]>> wrote:
>
>             I've used
>
>
>             |from dateutil import tz
>
>
>
>
>
>             from_zone = tz.tzutc()
>
>
>
>
>
>             to_zone = tz.tzlocal()
>
>
>
>
>
>             arrive = arrive.replace(tzinfo=from_zone)
>
>
>
>
>
>             arrive_central = arrive.astimezone(to_zone)|
>
>              
>
>             in hr_timesheet_invoice_create.py to output the correct
>             local time but that isn't working for me in some MAKO reports.
>
>             Do you know how to get the correct local time out of a MAKO
>             report?
>
>
>         Hello, AFAIK you always must compute in UTC, TZ comes from user
>         preferences.
>
>         Regards,
>
>
>             I look forward to hearing from you,
>             [hidden email]
>
>
>
>             _______________________________________________
>             Mailing list: https://launchpad.net/~openerp-community
>             Post to     : [hidden email]
>             <mailto:[hidden email]>
>             Unsubscribe : https://launchpad.net/~openerp-community
>             More help   : https://help.launchpad.net/ListHelp
>
>
>
>
>         --
>         Cristian Salamea
>         @ovnicraft
>
>
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openerp-community
> Post to     : [hidden email]
> Unsubscribe : https://launchpad.net/~openerp-community
> More help   : https://help.launchpad.net/ListHelp
>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] time zone adjustment in MAKO files?

DaleEMoore
Thanks Mike;

I very much appreciate your comments and time!

I'd just finished making something similar work:

import pytz
# ...
time_local
= 'America/Chicago'
time_fmt
= "%Y-%m-%d %H:%M"
arrive_dt
= datetime.utcnow()
testDt
=pytz.utc.localize(arrive_dt)
TestDt = testDt.astimezone(pytz.timezone(time_local))
Arrive=TestDt.strftime(time_fmt)
I appreciate you,
Dale


On Tue, May 14, 2013 at 2:37 AM, Michael Telahun Makonnen <[hidden email]> wrote:
Simply replacing timezone data does not work. You have to *convert* from
one timezone to another.  But, because openerp doesn't attach timezone
to the time in the database there is an initial step required to add utc
timezone data. The general steps are:
1. Convert date/time from db into a naive datetime object
2. Attach utc timezone to get a timezone aware date/time object
3. Convert it to the timezone of your choice

In practice it looks like this:

from pytz import timezone
tzutc = timezone('UTC')
tzlocal = timezone('America/Chicago')
dt = datetime.strptime(myobject.time_field, '%Y-%m-%d %H:%M:%S')
utc_dt = tzutc.localize(dt, is_dst=False)
local_dt = utc_dt.astimezone(tzlocal)

Regards,
Mike.

On 05/10/2013 07:52 PM, Dale E. Moore wrote:
> Does anyone know how to calculate local time in a mako report? This
>
> |from dateutil import tz
> from_zone = tz.tzutc()
> to_zone = tz.tzlocal()
> arrive = arrive.replace(tzinfo=from_zone)
> arrive_central = arrive.astimezone(to_zone)|
>
>
> is not working for me.
>
>
>
> On Fri, May 10, 2013 at 8:30 AM, Dale E. Moore <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Thanks for the feedback Cristian Salamea!
>
>     The user preferences are America/Chicago but what's being
>     displayed/printed is UTC.
>
>
>     On Fri, May 10, 2013 at 8:05 AM, Ovnicraft <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>
>
>
>         On Fri, May 10, 2013 at 7:32 AM, Dale E. Moore
>         <[hidden email] <mailto:[hidden email]>> wrote:
>
>             I've used
>
>
>             |from dateutil import tz
>
>
>
>
>
>             from_zone = tz.tzutc()
>
>
>
>
>
>             to_zone = tz.tzlocal()
>
>
>
>
>
>             arrive = arrive.replace(tzinfo=from_zone)
>
>
>
>
>
>             arrive_central = arrive.astimezone(to_zone)|
>
>
>
>             in hr_timesheet_invoice_create.py to output the correct
>             local time but that isn't working for me in some MAKO reports.
>
>             Do you know how to get the correct local time out of a MAKO
>             report?
>
>
>         Hello, AFAIK you always must compute in UTC, TZ comes from user
>         preferences.
>
>         Regards,
>
>
>             I look forward to hearing from you,
>             [hidden email]
>
>
>
>             _______________________________________________
>             Mailing list: https://launchpad.net/~openerp-community
>             Post to     : [hidden email]
>             <mailto:[hidden email]>
>             Unsubscribe : https://launchpad.net/~openerp-community
>             More help   : https://help.launchpad.net/ListHelp
>
>
>
>
>         --
>         Cristian Salamea
>         @ovnicraft
>
>
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openerp-community
> Post to     : [hidden email]
> Unsubscribe : https://launchpad.net/~openerp-community
> More help   : https://help.launchpad.net/ListHelp
>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp