How do you get the minute difference between two 12-hour dates encoded in a string like
"12:05am-02:55pm"
?
Short Answer
You shouldn’t. Get your data properly!
But Still…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CountingMinutesI(str) { | |
var times = str.replace(";\"","").split("-").map(function(t) { | |
t = t.split(":"); | |
var h = parseInt(t[0], 10); | |
var m = parseInt(t[1], 10); | |
var am = t[1].indexOf("am") > 0; | |
if(h === 12) h = 0; | |
var mins = m + h * 60; | |
if(!am) mins += 720; | |
return mins; | |
}); | |
var diff = times[1] - times[0]; | |
return diff > 0 ? diff : diff + 1440; | |
} |
I hate myself.