Created
          May 15, 2012 12:08 
        
      - 
      
 - 
        
Save egeozcan/2701255 to your computer and use it in GitHub Desktop.  
    Minute difference between two arbitrary string values
  
        
  
    
      This file contains hidden or 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; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Use it like:
CountingMinutesI("12:05am-02:55pm")