File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 39
39
function generateData ( ) {
40
40
var unit = document . getElementById ( 'unit' ) . value ;
41
41
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
+
42
50
// Returns true if outside 9:30am-4pm on a weekday
43
51
function outsideMarketHours ( date ) {
44
52
if ( date . isoWeekday ( ) > 5 ) {
45
53
return true ;
46
54
}
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 ) ) {
49
56
return true ;
50
57
}
51
58
return false ;
69
76
var data = [ ] ;
70
77
for ( ; data . length < 60 && date . isBefore ( now ) ; date = date . clone ( ) . add ( 1 , unit ) . startOf ( unit ) ) {
71
78
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 ( ) ) {
74
83
date = date . hour ( 9 ) . minute ( 30 ) . second ( 0 ) ;
75
84
}
76
85
}
You can’t perform that action at this time.
0 commit comments