1 # Parse a timezone specification.
3 # XXX Only the typical form "XXXhhYYY;ddd/hh,ddd/hh" is currently supported.
5 tzpat
= '^\([A-Z][A-Z][A-Z]\)\([-+]?[0-9]+\)\([A-Z][A-Z][A-Z]\);' + \
6 '\([0-9]+\)/\([0-9]+\),\([0-9]+\)/\([0-9]+\)$'
14 tzprog
= regex
.compile(tzpat
)
15 if tzprog
.match(tzstr
) < 0:
16 raise ValueError, 'not the TZ syntax I understand'
21 subs
.append(tzstr
[a
:b
])
22 for i
in (1, 3, 4, 5, 6):
23 subs
[i
] = eval(subs
[i
])
24 [tzname
, delta
, dstname
, daystart
, hourstart
, dayend
, hourend
] = subs
25 return (tzname
, delta
, dstname
, daystart
, hourstart
, dayend
, hourend
)
27 def tzlocaltime(secs
, params
):
29 (tzname
, delta
, dstname
, daystart
, hourstart
, dayend
, hourend
) = params
30 year
, month
, days
, hours
, mins
, secs
, yday
, wday
, isdst
= \
31 time
.gmtime(secs
- delta
*3600)
32 if (daystart
, hourstart
) <= (yday
+1, hours
) < (dayend
, hourend
):
35 return year
, month
, days
, hours
, mins
, secs
, yday
, wday
, tzname
38 global tzparams
, timezone
, altzone
, daylight
, tzname
40 tzstr
= os
.environ
['TZ']
41 tzparams
= tzparse(tzstr
)
42 timezone
= tzparams
[1] * 3600
43 altzone
= timezone
- 3600
45 tzname
= tzparams
[0], tzparams
[2]
49 (tzname
, delta
, dstname
, daystart
, hourstart
, dayend
, hourend
) = \
51 year
, month
, days
, hours
, mins
, secs
, yday
, wday
, isdst
= \
52 time
.gmtime(secs
- delta
*3600)
53 return (daystart
, hourstart
) <= (yday
+1, hours
) < (dayend
, hourend
)
58 return tzlocaltime(secs
, tzparams
)
61 from time
import asctime
, gmtime
66 print 'now =', now
, '=', asctime(tm
), x
[-1]
67 now
= now
- now
% (24*3600)
68 if sys
.argv
[1:]: now
= now
+ eval(sys
.argv
[1])
71 print 'gmtime =', now
, '=', asctime(tm
), 'yday =', x
[-2]
72 jan1
= now
- x
[-2]*24*3600
75 print 'jan1 =', jan1
, '=', asctime(tm
), x
[-1]
76 for d
in range(85, 95) + range(265, 275):
80 print 'd =', d
, 't =', t
, '=', asctime(tm
), x
[-1]