# -*- coding: UTF-8 -*- """ win32timezone: Module for handling datetime.tzinfo time zones using the windows registry for time zone information. The time zone names are dependent on the registry entries defined by the operating system. Currently, this module only supports the Windows NT line of products and not Windows 95/98/Me. This module may be tested using the doctest module. Written by Jason R. Coombs (jaraco@jaraco.com). Copyright © 2003. All Rights Reserved. To use this time zone module with the datetime module, simply pass the TimeZoneInfo object to the datetime constructor. For example, >>> import win32timezone, datetime >>> assert 'Mountain Standard Time' in win32timezone.GetTimeZoneNames() >>> tzi = TimeZoneInfo( 'Mountain Standard Time' ) >>> now = datetime.datetime.now( tzi ) The now object is now a time-zone aware object, and daylight savings- aware methods may be called on it. >>> now.utcoffset() in ( datetime.timedelta(-1, 61200), datetime.timedelta(-1, 64800) ) True (note that the result of utcoffset call will be different based on when now was generated, unless standard time is always used) >>> now = datetime.datetime.now( TimeZoneInfo( 'Mountain Standard Time', True ) ) >>> now.utcoffset() datetime.timedelta(-1, 61200) >>> aug2 = datetime.datetime( 2003, 8, 2, tzinfo = tzi ) >>> aug2.utctimetuple() (2003, 8, 2, 6, 0, 0, 5, 214, 0) >>> nov2 = datetime.datetime( 2003, 11, 2, tzinfo = tzi ) >>> nov2.utctimetuple() (2003, 11, 2, 7, 0, 0, 6, 306, 0) To convert from one timezone to another, just use the astimezone method. >>> aug2.isoformat() '2003-08-02T00:00:00-06:00' >>> aug2est = aug2.astimezone( win32timezone.TimeZoneInfo( 'Eastern Standard Time' ) ) >>> aug2est.isoformat() '2003-08-02T02:00:00-04:00' calling the displayName member will return the display name as set in the registry. >>> est = win32timezone.TimeZoneInfo( 'Eastern Standard Time' ) >>> est.displayName u'(GMT-05:00) Eastern Time (US & Canada)' >>> gmt = win32timezone.TimeZoneInfo( 'GMT Standard Time', True ) >>> gmt.displayName u'(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London' TimeZoneInfo now supports being pickled and comparison >>> import pickle >>> tz = win32timezone.TimeZoneInfo( 'China Standard Time' ) >>> tz == pickle.loads( pickle.dumps( tz ) ) True """ from __future__ import generators __author__ = 'Jason R. Coombs ' __version__ = '$Revision: 1.5 $'[11:-2] __vssauthor__ = '$Author: mhammond $'[9:-2] __date__ = '$Modtime: 04-04-14 10:52 $'[10:-2] import os, _winreg, struct, datetime class TimeZoneInfo( datetime.tzinfo ): """ Main class for handling win32 time zones. Usage: TimeZoneInfo(