Skip to content

Instantly share code, notes, and snippets.

@asfaltboy
Created November 8, 2012 09:16
Show Gist options
  • Save asfaltboy/4037702 to your computer and use it in GitHub Desktop.
Save asfaltboy/4037702 to your computer and use it in GitHub Desktop.
Calculate Percentage of a Trade Day
function getTradeDayPercent() {
// calculate the percent of time passed since trade opened in sydney
gmtoffset = (new Date).getTimezoneOffset() * 60 * 1000;
now = Date.now() + gmtoffset;
today = new Date(now).set({hour: 0, minute: 0, second: 0});
midnight = today.getTime()
hour = parseInt((now - midnight) / 1000 / 60 / 60);
if (hour < 17) today.addDays(-1);
gmt5 = today.set({hour: 17});
return ((now - gmt5.getTime() + gmtoffset) / 864000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment