Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Correct the time-string
- function timeCorrect(timestring) {
- console.log(timestring);
- var re = new RegExp(timestring);
- if (/\d\d:\d\d:\d\d/g.test(timestring)){
- var array = timestring.split(":");
- var secs = Number(array[2]);
- var mins = Number(array[1]);
- var hours = Number(array[0]);
- if(secs>59) {
- mins += Math.floor(secs/60);
- secs = (secs%60);
- if (secs < 10){ secs = "0" + secs; }
- }
- if(mins>59){
- hours += Math.floor(mins/60);
- mins = (mins%60);
- if (mins < 10){ mins = "0" + mins; }
- }
- if(mins>24){
- hours = (mins%24);
- if (hours < 10){ hours = "0" + hours; }
- }
- console.log( hours + ":" mins + ":" + secs);
- }
- else if ( timestring === ""){
- return "";
- }
- else {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement