Skip to content

Instantly share code, notes, and snippets.

@Fauntleroy
Created January 25, 2014 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fauntleroy/8610793 to your computer and use it in GitHub Desktop.
Save Fauntleroy/8610793 to your computer and use it in GitHub Desktop.
Convert a time offset string -HHMM into offset minutes.
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