[google-appengine] Re: handling timezones - problem using sample code
Replace 'datetime_module' with 'datetime' everywhere and add this line on top of your Python file: import datetime On Jan 25, 12:18 pm, jones34 wrote: > I'm trying to use timezones in my app. I understand the GAE decided > that this isn't something they really want to support well. I'm > trying to use the workaround suggested of creating my own timezone > classes based on the example code below from the GAE documentation. > It doesn't run. The exception I get is: > > : name 'datetime_module' is not defined > > Sorry I'm a python newbie, but what's missing? > > -- > > class Pacific_tzinfo(datetime_module.tzinfo): > """Implementation of the Pacific timezone.""" > def utcoffset(self, dt): > return datetime_module.timedelta(hours=-8) + self.dst(dt) > > def _FirstSunday(self, dt): > """First Sunday on or after dt.""" > return dt + datetime_module.timedelta(days=(6-dt.weekday())) > > def dst(self, dt): > # 2 am on the second Sunday in March > dst_start = self._FirstSunday(datetime_module.datetime(dt.year, 3, > 8, 2)) > # 1 am on the first Sunday in November > dst_end = self._FirstSunday(datetime_module.datetime(dt.year, 11, > 1, 1)) > > if dst_start <= dt.replace(tzinfo=None) < dst_end: > return datetime_module.timedelta(hours=1) > else: > return datetime_module.timedelta(hours=0) > > def tzname(self, dt): > if self.dst(dt) == datetime_module.timedelta(hours=0): > return "PST" > else: > return "PDT" > > pacific_time = utc_time.astimezone(Pacific_tzinfo()) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: handling timezones - problem using sample code
Thanks, but it still doesn't work. How do you convert the gae timestamp? It doesn't understand astimezone. On Jan 25, 2:42 am, Alexander Kojevnikov wrote: > Replace 'datetime_module' with 'datetime' everywhere and add this line > on top of your Python file: > > import datetime > > On Jan 25, 12:18 pm, jones34 wrote: > > > I'm trying to use timezones in my app. I understand the GAE decided > > that this isn't something they really want to support well. I'm > > trying to use the workaround suggested of creating my own timezone > > classes based on the example code below from the GAE documentation. > > It doesn't run. The exception I get is: > > > : name 'datetime_module' is not defined > > > Sorry I'm a python newbie, but what's missing? > > > -- > > > class Pacific_tzinfo(datetime_module.tzinfo): > > """Implementation of the Pacific timezone.""" > > def utcoffset(self, dt): > > return datetime_module.timedelta(hours=-8) + self.dst(dt) > > > def _FirstSunday(self, dt): > > """First Sunday on or after dt.""" > > return dt + datetime_module.timedelta(days=(6-dt.weekday())) > > > def dst(self, dt): > > # 2 am on the second Sunday in March > > dst_start = self._FirstSunday(datetime_module.datetime(dt.year, 3, > > 8, 2)) > > # 1 am on the first Sunday in November > > dst_end = self._FirstSunday(datetime_module.datetime(dt.year, 11, > > 1, 1)) > > > if dst_start <= dt.replace(tzinfo=None) < dst_end: > > return datetime_module.timedelta(hours=1) > > else: > > return datetime_module.timedelta(hours=0) > > > def tzname(self, dt): > > if self.dst(dt) == datetime_module.timedelta(hours=0): > > return "PST" > > else: > > return "PDT" > > > pacific_time = utc_time.astimezone(Pacific_tzinfo()) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: handling timezones - problem using sample code
> Thanks, but it still doesn't work. How do you convert the gae > timestamp? It doesn't understand astimezone. > 'astimezone' is a method of datetime.datetime class. Which type is your 'utc_time' variable? Could you post the code where it's initialised? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: handling timezones - problem using sample code
I'm trying simply to display a GAE timestamp in local (eastern time). I tried this, but it failed two different ways: note.create_date_time.replace(tzinfo=pytz.utc).astimezone (Eastern_tzinfo()). the display is attempted by invoking note.create_date _time in a template file in my dev environment, I import pytz and the code executes, but the value displayed is still in UTC when I invoke string format methods on note.create_date_time. If I deploy the code to GAE, I get a failure trying to import pytz. What I nee I appreciate your help. this _really_ should not be hard. Is there a simple way to get a utc timetamp to on both the client and the deployed environments? On Jan 25, 7:24 pm, Alexander Kojevnikov wrote: > > Thanks, but it still doesn't work. How do you convert the gae > > timestamp? It doesn't understand astimezone. > > 'astimezone' is a method of datetime.datetime class. Which type is > your 'utc_time' variable? Could you post the code where it's > initialised? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: handling timezones - problem using sample code
it's not a direct answer to your question, but http://timezones.appspot.com/ has some relevant info and code snippets. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: handling timezones - problem using sample code
I appreciate the pointer, but I've read the documentation and it, frankly, sucks. It's really dismaying that a company with the resources of Google is doing such a piss-poor job at delivering this toolkit. First of all, this simple thing should be trivial to solve - one line of code. The point of GAE is that it's supposed to be easy, right? Second, you shouldn't have to read 3 or 4 incomplete, poorly written, disjoint pieces of documentation to figure something out. It's not like this is a free service. Google really ought to ask themselves whether they want to do this and then look at the documentation Adobe, for example, provides for their tools. Even in Beta the Flex documentation and tools were orders of magnitude better than what Google provides. This is like, read the GAE "documentation", then read the django docs and figure out what does and does not apply, then read the docs for some python library, but we don't support it so you can't use it. Then write your own version of the python library and maybe you can do this thing that would be one line of code in Django or Java or any good toolkit. Ok two lines of code if you count the import statements. On Jan 26, 4:05 am, ryan wrote: > it's not a direct answer to your question, buthttp://timezones.appspot.com/ > has some relevant info and code snippets. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: handling timezones - problem using sample code
I'm able to import pytz fine in GAE...depending on what you need: from pytz import timezone from pytz import common_timezones import pytz then try: note.create_date_time.replace(tzinfo=pytz.utc).astimezone(timezone('US/Eastern')) Steve On Sun, Jan 25, 2009 at 9:49 PM, jones34 wrote: > > I'm trying simply to display a GAE timestamp in local (eastern time). > > I tried this, but it failed two different ways: > >note.create_date_time.replace(tzinfo=pytz.utc).astimezone > (Eastern_tzinfo()). > > the display is attempted by invoking note.create_date _time in > a template file > > in my dev environment, I import pytz and the code executes, but the > value displayed is still in UTC when I invoke string format methods on > note.create_date_time. > > If I deploy the code to GAE, I get a failure trying to import pytz. > What I nee > > I appreciate your help. this _really_ should not be hard. Is there a > simple way to get a utc timetamp to on both the client and the > deployed environments? > > On Jan 25, 7:24 pm, Alexander Kojevnikov > wrote: > > > Thanks, but it still doesn't work. How do you convert the gae > > > timestamp? It doesn't understand astimezone. > > > > 'astimezone' is a method of datetime.datetime class. Which type is > > your 'utc_time' variable? Could you post the code where it's > > initialised? > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: handling timezones - problem using sample code
On Jan 25, 6:49 pm, jones34 wrote: > > If I deploy the code to GAE, I get a failure trying to import pytz. are you including the pytz source with your app? pytz isn't provided automatically in production. (it's not provided in the sdk either, but i'm guessing you have it installed on the machine you're developing on, so your app is importing it from its installed location.) if you want to use pytz in production, you'll need to include it with the rest of your app's code, import it from there, and deploy a new version of your app with pytz to production. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---