Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
tzparse Namespace Reference

Functions

def tzparse
 
def tzlocaltime
 
def tzset
 
def isdst
 
def localtime
 
def test
 

Variables

tuple tzpat
 
 tzprog = None
 

Detailed Description

Parse a timezone specification.

Function Documentation

def tzparse.isdst (   secs)
Return true if daylight-saving time is in effect for the given
Unix time in the current timezone.

Definition at line 62 of file tzparse.py.

References tzset().

62 
63 def isdst(secs):
64  """Return true if daylight-saving time is in effect for the given
65  Unix time in the current timezone."""
66  import time
67  (tzname, delta, dstname, daystart, hourstart, dayend, hourend) = \
68  tzparams
69  year, month, days, hours, mins, secs, yday, wday, isdst = \
70  time.gmtime(secs - delta*3600)
71  return (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend)
72 
73 tzset()
def tzparse.localtime (   secs)
Get the local time in the current timezone.

Definition at line 74 of file tzparse.py.

References tzlocaltime().

74 
75 def localtime(secs):
76  """Get the local time in the current timezone."""
77  return tzlocaltime(secs, tzparams)
def tzparse.test ( )

Definition at line 78 of file tzparse.py.

References localtime().

78 
79 def test():
80  from time import asctime, gmtime
81  import time, sys
82  now = time.time()
83  x = localtime(now)
84  tm = x[:-1] + (0,)
85  print 'now =', now, '=', asctime(tm), x[-1]
86  now = now - now % (24*3600)
87  if sys.argv[1:]: now = now + eval(sys.argv[1])
88  x = gmtime(now)
89  tm = x[:-1] + (0,)
90  print 'gmtime =', now, '=', asctime(tm), 'yday =', x[-2]
91  jan1 = now - x[-2]*24*3600
92  x = localtime(jan1)
93  tm = x[:-1] + (0,)
94  print 'jan1 =', jan1, '=', asctime(tm), x[-1]
95  for d in range(85, 95) + range(265, 275):
96  t = jan1 + d*24*3600
97  x = localtime(t)
98  tm = x[:-1] + (0,)
99  print 'd =', d, 't =', t, '=', asctime(tm), x[-1]
def tzparse.tzlocaltime (   secs,
  params 
)
Given a Unix time in seconds and a tuple of information about
a timezone as returned by tzparse(), return the local time in the
form (year, month, day, hour, min, sec, yday, wday, tzname).

Definition at line 38 of file tzparse.py.

38 
39 def tzlocaltime(secs, params):
40  """Given a Unix time in seconds and a tuple of information about
41  a timezone as returned by tzparse(), return the local time in the
42  form (year, month, day, hour, min, sec, yday, wday, tzname)."""
43  import time
44  (tzname, delta, dstname, daystart, hourstart, dayend, hourend) = params
45  year, month, days, hours, mins, secs, yday, wday, isdst = \
46  time.gmtime(secs - delta*3600)
47  if (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend):
48  tzname = dstname
49  hours = hours + 1
50  return year, month, days, hours, mins, secs, yday, wday, tzname
def tzparse.tzparse (   tzstr)
Given a timezone spec, return a tuple of information
(tzname, delta, dstname, daystart, hourstart, dayend, hourend),
where 'tzname' is the name of the timezone, 'delta' is the offset
in hours from GMT, 'dstname' is the name of the daylight-saving
timezone, and 'daystart'/'hourstart' and 'dayend'/'hourend'
specify the starting and ending points for daylight saving time.

Definition at line 16 of file tzparse.py.

16 
17 def tzparse(tzstr):
18  """Given a timezone spec, return a tuple of information
19  (tzname, delta, dstname, daystart, hourstart, dayend, hourend),
20  where 'tzname' is the name of the timezone, 'delta' is the offset
21  in hours from GMT, 'dstname' is the name of the daylight-saving
22  timezone, and 'daystart'/'hourstart' and 'dayend'/'hourend'
23  specify the starting and ending points for daylight saving time."""
24  global tzprog
25  if tzprog is None:
26  import re
27  tzprog = re.compile(tzpat)
28  match = tzprog.match(tzstr)
29  if not match:
30  raise ValueError, 'not the TZ syntax I understand'
31  subs = []
32  for i in range(1, 8):
33  subs.append(match.group(i))
34  for i in (1, 3, 4, 5, 6):
35  subs[i] = eval(subs[i])
36  [tzname, delta, dstname, daystart, hourstart, dayend, hourend] = subs
37  return (tzname, delta, dstname, daystart, hourstart, dayend, hourend)
def tzparse.tzset ( )
Determine the current timezone from the "TZ" environment variable.

Definition at line 51 of file tzparse.py.

51 
52 def tzset():
53  """Determine the current timezone from the "TZ" environment variable."""
54  global tzparams, timezone, altzone, daylight, tzname
55  import os
56  tzstr = os.environ['TZ']
57  tzparams = tzparse(tzstr)
58  timezone = tzparams[1] * 3600
59  altzone = timezone - 3600
60  daylight = 1
61  tzname = tzparams[0], tzparams[2]

Variable Documentation

tuple tzpat
Initial value:
1 = ('^([A-Z][A-Z][A-Z])([-+]?[0-9]+)([A-Z][A-Z][A-Z]);'
2  '([0-9]+)/([0-9]+),([0-9]+)/([0-9]+)$')

Definition at line 11 of file tzparse.py.

tzprog = None

Definition at line 14 of file tzparse.py.