Skip to content

Commit 0b072aa

Browse files
committed
Start on Jan 1 for hour
1 parent 809b3d8 commit 0b072aa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

samples/scales/time/financial.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,20 @@
3939
function generateData() {
4040
var unit = document.getElementById('unit').value;
4141

42+
function unitLessThanDay() {
43+
return unit === 'second' || unit === 'minute' || unit === 'hour';
44+
}
45+
46+
function beforeNineThirty(date) {
47+
return date.hour() < 9 || (date.hour() === 9 && date.minute() < 30);
48+
}
49+
4250
// Returns true if outside 9:30am-4pm on a weekday
4351
function outsideMarketHours(date) {
4452
if (date.isoWeekday() > 5) {
4553
return true;
4654
}
47-
if ((unit === 'second' || unit === 'minute' || unit === 'hour')
48-
&& ((date.hour() < 9 && date.minute() < 30) || date.hour() > 16)) {
55+
if (unitLessThanDay() && (beforeNineThirty(date) || date.hour() > 16)) {
4956
return true;
5057
}
5158
return false;
@@ -69,8 +76,10 @@
6976
var data = [];
7077
for (; data.length < 60 && date.isBefore(now); date = date.clone().add(1, unit).startOf(unit)) {
7178
if (outsideMarketHours(date)) {
72-
date = date.clone().add(date.isoWeekday() > 5 ? 8 - date.isoWeekday() : 1, 'day');
73-
if ((unit === 'second' || unit === 'minute' || unit === 'hour')) {
79+
if (unitLessThanDay() && !beforeNineThirty(date)) {
80+
date = date.clone().add(date.isoWeekday() > 5 ? 8 - date.isoWeekday() : 1, 'day');
81+
}
82+
if (unitLessThanDay()) {
7483
date = date.hour(9).minute(30).second(0);
7584
}
7685
}

0 commit comments

Comments
 (0)