Skip to content

Instantly share code, notes, and snippets.

@takempf
Created January 25, 2014 02:20
Show Gist options
  • Select an option

  • Save takempf/8610793 to your computer and use it in GitHub Desktop.

Select an option

Save takempf/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