2828FARAWAY = 2000 , 2000
2929EVERYWHERE = ORIGIN , FARAWAY
3030
31- # TZDIFF = 5*3600 # THINK C 3.0 returns UCT if local time is EST
32- TZDIFF = 0 # THINK C 4.0 always returns local time
33-
3431
3532def main ():
3633 win = makewindow ()
@@ -89,11 +86,11 @@ def setdimensions(win):
8986 win .fullarea = ORIGIN , win .farcorner
9087
9188def settimer (win ):
92- now = getlocaltime ()
93- win .times = calctime (now )
94- delay = 61 - now % 60
89+ now = time . time ()
90+ hours , minutes , seconds = win .times = calctime (now )
91+ delay = 61 - seconds
9592 win .settimer (10 * delay )
96- minutes = ( now / 60 ) % 720
93+ minutes = minutes + hours * 60
9794 if win .ring :
9895 # Is it time to stop the alarm ringing?
9996 since = (minutes - win .time + 720 ) % 720
@@ -116,7 +113,7 @@ def drawproc(win, area):
116113 d .circle (win .center , win .radius )
117114 d .line (win .center , calcpoint (win , hours * 30 + minutes / 2 , 0.6 ))
118115 d .line (win .center , calcpoint (win , minutes * 6 , 1.0 ))
119- str = dd ( hours ) + ':' + dd ( minutes )
116+ str = "%02d:%02d" % ( hours , minutes )
120117 p = (win .width - d .textwidth (str ))/ 2 , win .height * 3 / 4
121118 d .text (p , str )
122119 if win .set :
@@ -177,7 +174,7 @@ def drawalarmtime(win, d):
177174 # Convert to hours (0..12) and minutes (12*(0..60))
178175 hh = win .time / 60
179176 mm = win .time % 60
180- str = 'Alarm@' + dd (hh ) + ':' + dd ( mm )
177+ str = 'Alarm@%02d:%02d' % (hh , mm )
181178 p1 = (win .width - d .textwidth (str ))/ 2 , win .height
182179 d .text (p1 , str )
183180
@@ -189,16 +186,8 @@ def calcpoint(win, degrees, size):
189186 return h + int (x * size * r ), v - int (y * size * r )
190187
191188def calctime (now ):
192- seconds = now % 60
193- minutes = (now / 60 ) % 60
194- hours = (now / 3600 ) % 12
189+ hours , minutes , seconds = time .localtime (now )[3 :6 ]
190+ hours = hours % 12
195191 return hours , minutes , seconds
196192
197- def dd (n ):
198- s = `n`
199- return '0' * (2 - len (s )) + s
200-
201- def getlocaltime ():
202- return int (time .time () - TZDIFF )
203-
204193main ()
0 commit comments