Skip to content

Instantly share code, notes, and snippets.

@aitor
Created June 5, 2010 19:14
Show Gist options
  • Save aitor/426913 to your computer and use it in GitHub Desktop.
Save aitor/426913 to your computer and use it in GitHub Desktop.
// Set the date for urls like
// http://0.0.0.0:3000/09-04-2012/08:24(+8)
// [date] [hour] [offset]
url = document.location;
var match = /http(s)?:\/\/(www.)?([^\/]+)\/(\d{2})-(\d{2})-(\d{4})\/(\d{2}):(\d{2})\(([-+]?\d+)\)/i.exec(url);
specific_date = { day: match[4], month: match[5] - 1, year: match[6] }
specific_time = { hours: parseInt(match[7], 10), minutes: match[8] }
specific_offset=parseInt(match[9], 10)
var now = new Date();
now.setFullYear(specific_date.year, specific_date.month, specific_date.day);
adjusted_offset = specific_offset + parseInt(now.getTimezoneOffset()/60)
adjusted_hour = specific_time.hours - adjusted_offset
var current = new Date(specific_date.year, specific_date.month, specific_date.day, adjusted_hour , specific_time.minutes, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment