Guest User

Untitled

a guest
Apr 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. def convert_to_seconds(timeduration):
  2. ...
  3.  
  4. convert_to_seconds("1h")
  5. -> 3600
  6.  
  7. convert_to_seconds("1d")
  8. -> 86400
  9.  
  10. seconds_per_unit = {"s": 1, "m": 60, "h": 3600, "d": 86400, "w": 604800}
  11.  
  12. def convert_to_seconds(s):
  13. return int(s[:-1]) * seconds_per_unit[s[-1]]
  14.  
  15. from datetime import timedelta
  16.  
  17. UNITS = {"s":"seconds", "m":"minutes", "h":"hours", "d":"days", "w":"weeks"}
  18.  
  19. def convert_to_seconds(s):
  20. count = int(s[:-1])
  21. unit = UNITS[ s[-1] ]
  22. td = timedelta(**{unit: count})
  23. return td.seconds + 60 * 60 * 24 * td.days
  24.  
  25. def f(x, y): pass
  26.  
  27. f(5, 6)
  28. f(x=5, y=6)
  29. f(y=6, x=5)
  30.  
  31. d = {"x": 5, "y": 6}
  32. f(**d)
  33.  
  34. long seconds = TextUtils.parsingStringToTimeInterval("5d").toSeconds();
Add Comment
Please, Sign In to add comment