PyScore

01: # -*- python -*-
02: ## sexagesimal.py ## python package PyScore.relational module sexagesimal ##
03: 
04: # PyScore
05: # a race scoring programme
06: # written by Matt Draisey
07: # 2004 April 6
08: 
09: reloadables=[]
10: 
11: ## sexagesimal.py ## python package PyScore.relational module sexagesimal ##
12: 
13: ######## ######## sexagesimal conversions ######## ########
14: 
15: def hms2int(hh,mm,ss):
16:     return (hh*60+mm)*60+ss
17: 
18: def int2hms(n):
19:     (hm,ss)=divmod(n,60)
20:     (hh,mm)=divmod(hm,60)
21:     return (hh,mm,ss)
22: 
23: def canonicalhms(*x):
24:     return int2hms(hms2int(*x))
25: 
26: def canonical12(*x):
27:     (hh,mm,ss)=int2hms(hms2int(*x))
28:     hh=hh%12
29:     if 4<=hh<12:
30:         return (hh+12,mm,ss)
31:     else:
32:         return (hh,mm,ss)
33: 
34: def canonical24(*x):
35:     (hh,mm,ss)=int2hms(hms2int(*x))
36:     return (hh%24,mm,ss)
37: 
38: ## sexagesimal.py ## python package PyScore.relational module sexagesimal ##