MCPcopy Create free account
hub / github.com/ActiveState/code / time

Function time

recipes/Python/578910_Humreadable_output_bytes/recipe-578910.py:35–87  ·  view source on GitHub ↗
(seconds=0)

Source from the content-addressed store, hash-verified

33 return unicode('%9s' % retv)
34
35def time(seconds=0):
36 # These are for convenience
37 minute = 60
38 hour = (minute**2)
39 day = (hour*24)
40 week = (day*7)
41 month = (week*4)
42 year = (month*12)
43
44 secs, mins, hrs, days, weeks, months, years = 0, 0, 0, 0, 0, 0, 0
45
46 if seconds > year:
47 years = (seconds / year)
48 tmp = (seconds % year)
49 seconds = tmp
50 if seconds > month:
51 months = (seconds / month)
52 tmp = (seconds % month)
53 seconds = tmp
54 if seconds > week:
55 weeks = (seconds / week)
56 tmp = (seconds % week)
57 seconds = tmp
58 if seconds > day:
59 days = (seconds / day)
60 tmp = (seconds % day)
61 seconds = tmp
62 if seconds > hour:
63 hrs = (seconds / hour)
64 tmp = (seconds % hour)
65 seconds = tmp
66 if seconds > minute:
67 mins = (seconds / minute)
68 secs = (seconds % minute)
69 if seconds < minute:
70 secs = seconds
71
72 if years != 0:
73 return unicode('%4dy%2dm%1dw%1dd %02d:%02d:%02d' % (
74 years, months, weeks, days, hrs, mins, secs
75 ))
76 if months != 0:
77 return unicode('%2dm%1dw%1dd %02d:%02d:%02d' % (
78 months, weeks, days, hrs, mins, secs
79 ))
80 if weeks != 0:
81 return unicode('%1dw%1dd %02d:%02d:%02d' % (
82 weeks, days, hrs, mins, secs
83 ))
84 if days != 0:
85 return unicode('%1dd %02d:%02d:%02d' % (days, hrs, mins, secs))
86
87 return unicode('%02d:%02d:%02d' % (hrs, mins, secs))

Callers 15

__init__Method · 0.85
consumeMethod · 0.85
acquireReadMethod · 0.85
acquireWriteMethod · 0.85
__init__Method · 0.85
get_tokensMethod · 0.85
__init__Method · 0.85
_setNewestMethod · 0.85
pruneMethod · 0.85
gen_passwdFunction · 0.85
gen_num_passwdFunction · 0.85
gen_char_passwdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected