Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // Correct the time-string
  2.  
  3. function timeCorrect(timestring) {
  4. console.log(timestring);
  5.  
  6. var re = new RegExp(timestring);
  7.  
  8. if (/\d\d:\d\d:\d\d/g.test(timestring)){
  9. var array = timestring.split(":");
  10. var secs = Number(array[2]);
  11. var mins = Number(array[1]);
  12. var hours = Number(array[0]);
  13.  
  14. if(secs>59) {
  15. mins += Math.floor(secs/60);
  16. secs = (secs%60);
  17. if (secs < 10){ secs = "0" + secs; }
  18. }
  19. if(mins>59){
  20. hours += Math.floor(mins/60);
  21. mins = (mins%60);
  22. if (mins < 10){ mins = "0" + mins; }
  23. }
  24. if(mins>24){
  25. hours = (mins%24);
  26. if (hours < 10){ hours = "0" + hours; }
  27. }
  28. console.log( hours + ":" mins + ":" + secs);
  29. }
  30. else if ( timestring === ""){
  31. return "";
  32. }
  33. else {
  34. return null;
  35. }
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement