473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Python and timezones

I'm trying to write some code to deal with world timezones, and I'm
getting a strange result. America/Iqaluit should not be showing up in
UTC+00:00, but it is. Can anyone see what's wrong with this code?
import time
from datetime import datetime
import os
import pytz

def getZoneNamesOnThisComputer():
for i in pytz.all_timezones:
if os.path.exists( os.path.join('/tmp/usr/share/zoneinfo/',
i)):
yield i
def getZonesGroupedByOffset():
'''return a dict of all the zone names , grouped by their offset
eg:
{'-0400': ['America/Blanc-Sablon', 'Etc/GMT+4'],
'+0000': ['America/Iqaluit', 'Etc/GMT', 'Europe/Belfast', 'GB',
'GMT'],
...
}
'''
Y,M,D,h,m,s = time.localtime()[:6]

zonesGroupedByOffset = {}

for name in getZoneNamesOnThisComputer():
tz = pytz.timezone(name)
now = datetime(Y,M,D,h,m,s, tzinfo=tz)
# strfime returns a string like "-0800" or "+0430" or "0000"
offsetKey = now.strftime('%z')
if not zonesGroupedByOffset.has_key(offsetKey):
zonesGroupedByOffset[offsetKey] = []
zonesGroupedByOffset[offsetKey].append(name)
return zonesGroupedByOffset
z = getZonesGroupedByOffset()
print z['+0000']

# Why is America/Iqaluit showing up here???
Jul 2 '08 #1
0 790

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Michael | last post by:
I would like to set the timezone of a thread to allow me to calculate the UTC time for data sourced from a number of time zones. Although this can be done in C and C++, I annot find how to do...
0
by: Robert Treat | last post by:
I am trying to figure out if there is a way to determine the timezones supported in postgresql from within the database. If you look at...
25
by: abhinav | last post by:
Hello guys, I am a novice in python.I have to implement a full fledged mail server ..But i am not able to choose the language.Should i go for C(socket API) or python for this project? What are the...
1
by: Flack | last post by:
Hey guys, I need to compare two times that the user selects. The user selects the hour, date, and timezone (which can be either NY, LN, or HK timezones). How can I compare two dates of...
24
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several...
7
by: David T. Ashley | last post by:
In a web database (PHP), per user, I'd like to allow each user to specify their timezone (this would change how times are adjusted for display for that user). How do I enumerate all possible...
27
by: Sanjay | last post by:
Hi All, I am using pytz.common_timezones to populate the timezone combo box of some user registration form. But as it has so many timezones (around 400), it is a bit confusing to the users. Is...
5
by: lukasz.f24 | last post by:
Hello, Is there any build in solution in python to handle timezones? My problem is I have to convert +4 time to +0. In the worst case i can just add +4 to the houer but I'm not very happy about...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.