Skip to content

Commit

Permalink
Start on Jan 1 for hour
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed May 6, 2019
1 parent 809b3d8 commit 760a4e5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions samples/scales/time/financial.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@
function generateData() {
var unit = document.getElementById('unit').value;

function unitLessThanDay(unit) {
return unit === 'second' || unit === 'minute' || unit === 'hour';
}

function beforeNineThirty(date) {
return date.hour() < 9 || (date.hour() == 9 && date.minute() < 30);
}

// Returns true if outside 9:30am-4pm on a weekday
function outsideMarketHours(date) {
if (date.isoWeekday() > 5) {
return true;
}
if ((unit === 'second' || unit === 'minute' || unit === 'hour')
&& ((date.hour() < 9 && date.minute() < 30) || date.hour() > 16)) {
if (unitLessThanDay(unit) && (beforeNineThirty(date) || date.hour() > 16)) {
return true;
}
return false;
Expand All @@ -69,8 +76,10 @@
var data = [];
for (; data.length < 60 && date.isBefore(now); date = date.clone().add(1, unit).startOf(unit)) {
if (outsideMarketHours(date)) {
date = date.clone().add(date.isoWeekday() > 5 ? 8 - date.isoWeekday() : 1, 'day');
if ((unit === 'second' || unit === 'minute' || unit === 'hour')) {
if (unitLessThanDay(unit) && !beforeNineThirty(date)) {
date = date.clone().add(date.isoWeekday() > 5 ? 8 - date.isoWeekday() : 1, 'day');
}
if (unitLessThanDay(unit)) {
date = date.hour(9).minute(30).second(0);
}
}
Expand Down

0 comments on commit 760a4e5

Please sign in to comment.