Created
January 25, 2014 02:20
-
-
Save Fauntleroy/8610793 to your computer and use it in GitHub Desktop.
Convert a time offset string -HHMM into offset minutes.
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
var convertOffset = function( offset ){ | |
if( typeof offset !== 'string' ) return; | |
var hours = parseInt( offset.substr( -4, 2 ), 10 ); | |
var minutes = parseInt( offset.substr( -2, 2 ), 10 ); | |
var negative = ( offset.substr( -5, 1 ) === '-' ); | |
var offset_in_minutes = hours * 60 + minutes; | |
if( negative ) offset_in_minutes = offset_in_minutes * -1; | |
return offset_in_minutes; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment