Server IP : 127.0.0.2 / Your IP : 3.148.211.202 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/python2.7/dist-packages/vobject/ |
Upload File : |
import _winreg import struct import datetime handle=_winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE) tzparent=_winreg.OpenKey(handle, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones") parentsize=_winreg.QueryInfoKey(tzparent)[0] localkey=_winreg.OpenKey(handle, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation") WEEKS=datetime.timedelta(7) def list_timezones(): """Return a list of all time zones known to the system.""" l=[] for i in xrange(parentsize): l.append(_winreg.EnumKey(tzparent, i)) return l class win32tz(datetime.tzinfo): """tzinfo class based on win32's timezones available in the registry. >>> local = win32tz('Central Standard Time') >>> oct1 = datetime.datetime(month=10, year=2004, day=1, tzinfo=local) >>> dec1 = datetime.datetime(month=12, year=2004, day=1, tzinfo=local) >>> oct1.dst() datetime.timedelta(0, 3600) >>> dec1.dst() datetime.timedelta(0) >>> braz = win32tz('E. South America Standard Time') >>> braz.dst(oct1) datetime.timedelta(0) >>> braz.dst(dec1) datetime.timedelta(0, 3600) """ def __init__(self, name): self.data=win32tz_data(name) def utcoffset(self, dt): if self._isdst(dt): return datetime.timedelta(minutes=self.data.dstoffset) else: return datetime.timedelta(minutes=self.data.stdoffset) def dst(self, dt): if self._isdst(dt): minutes = self.data.dstoffset - self.data.stdoffset return datetime.timedelta(minutes=minutes) else: return datetime.timedelta(0) def tzname(self, dt): if self._isdst(dt): return self.data.dstname else: return self.data.stdname def _isdst(self, dt): dat=self.data dston = pickNthWeekday(dt.year, dat.dstmonth, dat.dstdayofweek, dat.dsthour, dat.dstminute, dat.dstweeknumber) dstoff = pickNthWeekday(dt.year, dat.stdmonth, dat.stddayofweek, dat.stdhour, dat.stdminute, dat.stdweeknumber) if dston < dstoff: if dston <= dt.replace(tzinfo=None) < dstoff: return True else: return False else: if dstoff <= dt.replace(tzinfo=None) < dston: return False else: return True def __repr__(self): return "<win32tz - %s>" % self.data.display def pickNthWeekday(year, month, dayofweek, hour, minute, whichweek): """dayofweek == 0 means Sunday, whichweek > 4 means last instance""" first = datetime.datetime(year=year, month=month, hour=hour, minute=minute, day=1) weekdayone = first.replace(day=((dayofweek - first.isoweekday()) % 7 + 1)) for n in xrange(whichweek - 1, -1, -1): dt=weekdayone + n * WEEKS if dt.month == month: return dt class win32tz_data(object): """Read a registry key for a timezone, expose its contents.""" def __init__(self, path): """Load path, or if path is empty, load local time.""" if path: keydict=valuesToDict(_winreg.OpenKey(tzparent, path)) self.display = keydict['Display'] self.dstname = keydict['Dlt'] self.stdname = keydict['Std'] #see http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm tup = struct.unpack('=3l16h', keydict['TZI']) self.stdoffset = -tup[0]-tup[1] #Bias + StandardBias * -1 self.dstoffset = self.stdoffset - tup[2] # + DaylightBias * -1 offset=3 self.stdmonth = tup[1 + offset] self.stddayofweek = tup[2 + offset] #Sunday=0 self.stdweeknumber = tup[3 + offset] #Last = 5 self.stdhour = tup[4 + offset] self.stdminute = tup[5 + offset] offset=11 self.dstmonth = tup[1 + offset] self.dstdayofweek = tup[2 + offset] #Sunday=0 self.dstweeknumber = tup[3 + offset] #Last = 5 self.dsthour = tup[4 + offset] self.dstminute = tup[5 + offset] else: keydict=valuesToDict(localkey) self.stdname = keydict['StandardName'] self.dstname = keydict['DaylightName'] sourcekey=_winreg.OpenKey(tzparent, self.stdname) self.display = valuesToDict(sourcekey)['Display'] self.stdoffset = -keydict['Bias']-keydict['StandardBias'] self.dstoffset = self.stdoffset - keydict['DaylightBias'] #see http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm tup = struct.unpack('=8h', keydict['StandardStart']) offset=0 self.stdmonth = tup[1 + offset] self.stddayofweek = tup[2 + offset] #Sunday=0 self.stdweeknumber = tup[3 + offset] #Last = 5 self.stdhour = tup[4 + offset] self.stdminute = tup[5 + offset] tup = struct.unpack('=8h', keydict['DaylightStart']) self.dstmonth = tup[1 + offset] self.dstdayofweek = tup[2 + offset] #Sunday=0 self.dstweeknumber = tup[3 + offset] #Last = 5 self.dsthour = tup[4 + offset] self.dstminute = tup[5 + offset] def valuesToDict(key): """Convert a registry key's values to a dictionary.""" dict={} size=_winreg.QueryInfoKey(key)[1] for i in xrange(size): dict[_winreg.EnumValue(key, i)[0]]=_winreg.EnumValue(key, i)[1] return dict def _test(): import win32tz, doctest doctest.testmod(win32tz, verbose=0) if __name__ == '__main__': _test()