noftaly

Untitled

Jun 8th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. # =====> Verifier si le temps est bien écris
  2. function CheckTime(time: text) :: boolean:
  3. if length of {_time} is 2:
  4. set {_check::*} to groups 0 of "%{_time}%" matched to "^[0-9](s|S|m|M|h|H|d|D)$"
  5. else if length of {_time} is 3:
  6. set {_check::*} to groups 0 of "%{_time}%" matched to "^[0-9]{2}(s|S|m|M|h|H|d|D)$"
  7. if {_check::*} is set:
  8. return true
  9. else:
  10. return false
  11.  
  12. # =====> Retourner le temps en TimeSpan (pour Skript)
  13. function TransformTime(time: text) :: timespan:
  14. if length of {_time} is 2:
  15. set {_time} to "0%{_time}%"
  16. set {_characters::*} to {_time} split at ""
  17. if {_characters::3} is "s":
  18. set {_characters::3} to " seconds"
  19. else if {_characters::3} is "m":
  20. set {_characters::3} to " minutes"
  21. else if {_characters::3} is "h":
  22. set {_characters::3} to " hours"
  23. else if {_characters::3} is "d":
  24. set {_characters::3} to " days"
  25. set {_result} to "%{_characters::1}%%{_characters::2}%%{_characters::3}%" parsed as timespan
  26. return {_result}
  27.  
  28. # =====> Retourner le temps en temps normal (en francais)
  29. function SanctionTime(time: timespan) :: text:
  30. set {_time} to "%{_time}%"
  31. set {_words::*} to {_time} split at " "
  32. if {_words::2} is "second" or "seconds":
  33. set {_words::2} to "seconde(s)"
  34. else if {_words::2} is "minute" or "minutes":
  35. set {_words::2} to "minute(s)"
  36. else if {_words::2} is "hour" or "hours":
  37. set {_words::2} to "heure(s)"
  38. else if {_words::2} is "day" or "days":
  39. set {_words::2} to "jour(s)"
  40. set {_result} to "%{_words::1}% %{_words::2}%"
  41. return {_result}
Advertisement
Add Comment
Please, Sign In to add comment