File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 37
37
< button id ="update "> update</ button >
38
38
< script >
39
39
function generateData ( ) {
40
+ /**
41
+ * Returns true if outside 9:30am-4pm on a weekday
42
+ */
43
+ function outsideMarketHours ( date ) {
44
+ if ( date . isoWeekday ( ) > 5 ) {
45
+ return true ;
46
+ }
47
+ if ( ( unit == 'second' || unit == 'minute' || unit == 'hour' )
48
+ && ( ( date . hour ( ) < 9 && date . minute ( ) < 30 ) || date . hour ( ) > 16 ) ) {
49
+ return true ;
50
+ }
51
+ return false ;
52
+ }
53
+
40
54
function randomNumber ( min , max ) {
41
55
return Math . random ( ) * ( max - min ) + min ;
42
56
}
54
68
var now = moment ( ) ;
55
69
var data = [ ] ;
56
70
var unit = document . getElementById ( 'unit' ) . value ;
57
- for ( ; data . length < 60 && date . isBefore ( now ) ; date = date . clone ( ) . add ( 1 , unit ) ) {
58
- if ( date . isoWeekday ( ) <= 5 ) {
59
- data . push ( randomBar ( date , data . length > 0 ? data [ data . length - 1 ] . y : 30 ) ) ;
71
+ for ( ; data . length < 60 && date . isBefore ( now ) ; date = date . clone ( ) . add ( 1 , unit ) . startOf ( unit ) ) {
72
+ if ( outsideMarketHours ( date ) ) {
73
+ date = date . clone ( ) . add ( 8 - date . isoWeekday ( ) , 'day' ) ;
74
+ if ( ( unit == 'second' || unit == 'minute' || unit == 'hour' ) ) {
75
+ date = date . hour ( 9 ) . minute ( 30 ) . second ( 0 ) ;
76
+ }
60
77
}
78
+ data . push ( randomBar ( date , data . length > 0 ? data [ data . length - 1 ] . y : 30 ) ) ;
61
79
}
62
80
63
81
return data ;
You can’t perform that action at this time.
0 commit comments