Akuba

sectostr

Jul 26th, 2016
291
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import time
  2.  
  3. def sectostr(t):
  4.     _time = ""
  5.     (t, _time) = sectostr_one(31536000, "year",   "years", "one", t, _time)
  6.     (t, _time) = sectostr_one(604800,   "week",   "weeks", "one", t, _time)
  7.     (t, _time) = sectostr_one(86400,    "day",    "days",  "one", t, _time)
  8.     (t, _time) = sectostr_one(3600,     "hour",   "hours", "one", t, _time)
  9.     (t, _time) = sectostr_one(60,       "minute", "minutes", "one", t, _time)
  10.     (t, _time) = sectostr_one(1,        "second", "seconds", "one", t, _time)
  11.  
  12.     if not len(_time):
  13.         _time = "0 seconds"
  14.  
  15.     return _time
  16.  
  17. def sectostr_one (x, cap, cappl, capone, t, _time):
  18.  
  19.     if t >= x:
  20.         num = int(t / x)
  21.         t = t % x
  22.         if len(_time) != 0:
  23.             if t > 0:
  24.                 _time = _time + ", "
  25.             else:
  26.                 _time = _time + " and "
  27.         if num > 1:
  28.             _time = _time + str(num) + " " + cappl
  29.         else:
  30.             _time = _time + capone + " " + cap
  31.     return (t, _time)
  32.  
  33. print (sectostr(355345))
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment