-
Notifications
You must be signed in to change notification settings - Fork 47
/
checksession.html
153 lines (130 loc) · 11.2 KB
/
checksession.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<style>
.input-text {
margin: 10px 0;
}
.results {
margin-top: 10px;
word-break: break-all;
}
table {
width: 100%;
}
tr {
border-top: none;
color:#666B85;
font-size:16px;
font-weight:normal;
text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);
}
tr:first-child {
border-top:none;
}
tr:last-child {
border-bottom:none;
}
tr:nth-child(odd) td {
background:#EBEBEB;
}
tr:last-child td:first-child {
border-bottom-left-radius:3px;
}
tr:last-child td:last-child {
border-bottom-right-radius:3px;
}
td {
background:#FFFFFF;
padding:20px;
text-align:left;
vertical-align:middle;
font-weight:300;
font-size:18px;
border-right: 1px solid #C1C3D1;
}
td:last-child {
border-right: 0px;
}
th.text-left {
text-align: left;
}
th.text-center {
text-align: center;
}
th.text-right {
text-align: right;
}
td.text-left {
text-align: left;
}
td.text-center {
text-align: center;
}
td.text-right {
text-align: right;
}
.table-fill {
background: white;
border-radius:3px;
border-collapse: collapse;
min-height: 320px;
margin: auto;
max-width: 600px;
padding:5px;
width: 100%;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
padding: 15px;
}
.input-field {
width: 100%;
font-size: 20px;
line-height: 1.5;
margin-bottom: 10px;
padding: 0 5px;
}
table {
border-collapse: collapse;
}
</style>
</head>
<script>
var sessionFormatter=function(){function D(b,z){if(!Number.isFinite(b))return"n/a";if(!Number.isInteger(z))throw new TypeError("invalid length");if(0>z||16<z)throw new TypeError("invalid length");return 0===z?b.toString():("0000000000000000"+b.toString()).slice(-z)}function T(b){"Asia/Bahrain"===b&&(b="Asia/Kuwait"),this._name=b;var z=R[b];if(z||(z={time:[],offset:[]},this._invalid=!0),z.time.length!==z.offset.length&&(z={time:[],offset:[]},this._invalid=!0),!z.time_utc){for(var L=z.time,J=z.offset,j=L.length,Q=Array(j),q=0;q<j;q++)L[q]*=1e3,J[q]*=1e3,Q[q]=L[q]-J[q];z.time_utc=Q}this.tz=z}function O(b,z){return b.compareTo(z)}function k(b){b>H.minutesPerDay&&(b-=H.minutesPerDay);var z=b%60;return D((b-z)/60,2)+":"+D(z,2)}function S(b){return b.match(N)[0]}function Y(b,z){var L=S(b),J=S(z);return F[L]>F[J]}function U(b,z,L){return void 0===L?moment.weekdaysMin(z-1)+" "+b:moment.weekdaysMin(z-1)+"-"+moment.weekdaysMin(L-1)+" "+b}function C(b){return 1===b?7:b-1}function W(b,z){if(z){var L=b[0];b.unshift(C(L))}}function w(b){var z=function(L){return L.reduce(function(J,j){var Q=k(j.alignedStart())+"-"+k(j.alignedStart()+j.length()),q=j.dayOfWeek();return J.hasOwnProperty(Q)?J[Q].push(q):J[Q]=[q],J},{})}(b);return Object.keys(z).reduce(function(L,J){var j=z[J].sort(),Q=J.split("-"),q=H.get_minutes_from_hhmm(Q[0])>=H.get_minutes_from_hhmm(Q[1]);if(1===j.length)W(j,q),L.push(U(J,j[0]));else{var Z=[];j.forEach(function(V,X){var $=j[X+1];$&&V===$-1?Z.push(V):V===Z[Z.length-1]+1?(Z.push(V),W(Z,q),L.push(U(J,Z[0],Z[Z.length-1])),Z.splice(0,Z.length)):L.push(function(G,ee,te){return te?U(G,C(ee),ee):U(G,ee)}(J,V,q))})}return L},[]).sort(Y)}var M=[2,3,4,5,6,7,1].map(function(b){return moment.weekdaysMin(b-1)}),N=new RegExp(M.join("|")),F=M.reduce(function(b,z,L){return b[z]=L+1,b},{}),R={};T.prototype.offset_utc=function(b){return T._offset(this.tz.time_utc,this.tz.offset,b)},T.prototype.offset_loc=function(b){return T._offset(this.tz.time,this.tz.offset,b)},T.prototype.is_valid=function(){return!this._invalid},T._offset=function(b,z,L){var J=function(j,Q){var q=j.length;if(0===q)return-1;if(isNaN(Q))throw Error("Key is NaN");for(var Z=0,V=q-1,X=P((Z+V)/2);;){if(j[X]>Q){if((V=X-1)<Z)return X;}else if(Z=X+1,V<Z)return X<q-1?X+1:-1;X=P((Z+V)/2)}}(b,L);return-1===J?0:z[J]};var P=function(b){return 0|b},x=function(b){return 1e3*(60*b)},H={SUNDAY:1,MONDAY:2,TUESDAY:3,WEDNESDAY:4,THURSDAY:5,FRIDAY:6,SATURDAY:7,JANUARY:0,DECEMBER:11,YEAR:1,MONTH:2,WEEK_OF_YEAR:3,DAY_OF_MONTH:5,DAY_OF_YEAR:6,DAY_OF_WEEK:7,HOUR_OF_DAY:11,MINUTE:12,SECOND:13,minutesPerDay:1440,secondsPerDay:x(1440),get_minutes_from_hhmm:function(b){return-1!==b.indexOf(":")&&(b=b.split(":").join("")),b%100+60*P(b/100)},get_year:function(b){return b.getUTCFullYear()},get_month:function(b){return b.getUTCMonth()},get_hours:function(b){return b.getUTCHours()},get_minutes:function(b){return b.getUTCMinutes()},get_seconds:function(b){return b.getUTCSeconds()},get_day_of_month:function(b){return b.getUTCDate()},get_day_of_week:function(b){return b.getUTCDay()+1},get_day_of_year:function(b){var z=Date.UTC(b.getUTCFullYear(),0,1,0,0,0,0);return P((b.getTime()-z)/api.secondsPerDay)+1},get_week_of_year:function(b){var z=Date.UTC(b.getUTCFullYear(),0,1,0,0,0,0),L=api.clone(b);return api.set_hms(L,0,0,0,0),L.setUTCDate(L.getUTCDate()+4-(L.getUTCDay()||7)),P(((L.getTime()-z)/api.secondsPerDay+1)/7)},get_minutes_from_midnight:function(b){return 60*api.get_hours(b)+api.get_minutes(b)},set_hms:function(b,z,L,J,j){b.setUTCHours(z),b.setUTCMinutes(L),b.setUTCSeconds(J),b.setUTCMilliseconds(j)},add_days_considering_dst:function(b,z,L){var J=b.offset_utc(z),j=this.clone(z);this.add_date(j,L);var Q=b.offset_utc(j);return j.setTime(j.getTime()+J-Q),j},add_date:function(b,z){b.setTime(b.getTime()+z*api.secondsPerDay)},clone:function(b){return new Date(b.getTime())},get_days_per_year:function(b){var z=b.getUTCFullYear();return this.days_per_year(z)},days_per_year:function(b){return 0!=b%4||0==b%100&&0!=b%400?365:366},get_part:function(b,z){return z===api.YEAR?api.get_year(b):z===api.MONTH?api.get_month(b):z===api.DAY_OF_MONTH?api.get_day_of_month(b):z===api.WEEK_OF_YEAR?api.get_week_of_year(b):z===api.DAY_OF_WEEK?api.get_day_of_week(b):z===api.HOUR_OF_DAY?api.get_hours(b):z===api.MINUTE?api.get_minutes(b):z===api.DAY_OF_YEAR?api.get_day_of_year(b):z===api.SECOND?api.get_seconds(b):b.getTime()},time_minutes:x,time_seconds:function(b){return 1e3*b},time_minutes_diff:function(b,z){return P((P(b/1e3)-P(z/1e3))/60)},time_seconds_diff:function(b,z){return P(P(b/1e3)-P(z/1e3))},utc_to_cal:function(b,z){var L=b.offset_utc(z);return new Date(z+L)},get_cal:function(b,z,L,J){var j=new Date(Date.UTC(z,L,J)),Q=b.offset_utc(+j);return new Date(j.valueOf()-Q)},get_cal_utc:function(b,z,L){return new Date(Date.UTC(b,z,L))},cal_to_utc:function(b,z){var L=z.getTime();return L-b.offset_loc(L)},get_timezone:function(b){return new T(b)},shift_day:function(b,z){var L=b-1;return 6<(L+=z)?L%=7:0>L&&(L=(7+L%7)%7),L+1}};const v=[H.MONDAY,H.TUESDAY,H.WEDNESDAY,H.THURSDAY,H.FRIDAY],B=[H.SUNDAY,H.MONDAY,H.TUESDAY,H.WEDNESDAY,H.THURSDAY,H.FRIDAY,H.SATURDAY];var K=function(){function b(z,L,J){this._dayOfWeek=z,this._start=L,this._length=J}return b.prototype.start=function(){return this._start},b.prototype.alignedStart=function(){return 0>this._start?this._start+H.minutesPerDay:this._start},b.prototype.isOvernight=function(){return 0>this._start},b.prototype.dayOfWeek=function(){return this._dayOfWeek},b.prototype.length=function(){return this._length},b.prototype.weight=function(){return this._dayOfWeek*H.minutesPerDay+this._start},b.prototype.compareTo=function(z){var L=this.weight(),J=L+this._length,j=z.weight();return L<=j&&j<J?0:L>j?1:-1},b}(),I=function(){function b(z){void 0===z&&(z="0000-0000");var L=this;this._entries=[],this._firstDayOfWeek=H.MONDAY,this._weekEndsCount=null,"24x7"===z.toLowerCase()?B.forEach(function(J){L.addSessionEntry(J,0,0)}):this._parseSpec(z),this._entries.sort(O)}return b.prototype.entries=function(){return this._entries},b.prototype.firstDayOfWeek=function(){return this._firstDayOfWeek},b.prototype.addSessionEntry=function(z,L,J){J<=L&&0!==L&&(L-=H.minutesPerDay);var j=J===L?H.minutesPerDay:J-L;this._entries.push(new K(z,L,j))},b.prototype.isWeekEnd=function(z){var L=lowerbound(this._entries,new K(z,0,0),function(J,j){return J.dayOfWeek()<j.dayOfWeek()});return L>this._entries.length-1||this._entries[L].dayOfWeek()!==z},b.prototype.weekEndsCount=function(){if(null===this._weekEndsCount){var z={};this._entries.forEach(function(L){z[L.dayOfWeek()]=1}),this._weekEndsCount=7-Object.keys(z).reduce(function(L,J){return L+(z[+J]||0)},0)}return this._weekEndsCount},b.prototype.hasWeekEnds=function(){return 0<this.weekEndsCount()},b.prototype.indexOfSessionEntry=function(z,L){var J=lowerbound(this._entries,new K(z,L,0),function(j,Q){return 0>j.compareTo(Q)});return J>this._entries.length-1?0:J},b.prototype.findSessionEntry=function(z,L){return this._entries[this.indexOfSessionEntry(z,L)]},b.prototype.correctTradingDay=function(z,L){var J=H.get_day_of_week(z),j=60*H.get_hours(z)+H.get_minutes(z),Q=(this.findSessionEntry(J,j).dayOfWeek()-J+7)%7;return 0==Q?z:H.add_days_considering_dst(L,z,Q)},b.prototype.alignToSessionStart=function(z,L){var J=H.get_day_of_week(z),j=H.get_minutes_from_midnight(z),Q=this.findSessionEntry(J,j),q=Q.alignedStart(),Z=(Q.dayOfWeek()-J+7)%7-(Q.isOvernight()?1:0);return 0!=Z&&H.add_date(z,Z),H.set_hms(z,0|q/60,q%60,0,0),function(V,X,$){var G=new Date(X.valueOf()+6e4*V);return V+($.offset_loc(X)/6e4-$.offset_loc(G)/6e4)}(Q.length(),z,L)},b.prototype._parseSpec=function(z){var L=this,J={},j=!1;(z=this._parseFirstDayOfWeek(z)).split("|").forEach(function(Q){var q=Q.split(":");if(1!==q.length&&2!==q.length)throw new Error("Bad session section: "+Q);var Z=1===q.length;if(Z){if(j)throw new Error("Duplicated default section: "+Q);j=!0}(Z?v:function(V){return Array.from(V).reduce(function(X,$){var G=+$;return-1===X.indexOf(G)&&X.push(G),X},[])}(q[1])).forEach(function(V){Z&&J[V]||(J[V]=q[0])})}),B.forEach(function(Q){var q=J[Q];void 0!==q&&q.split(",").forEach(function(Z){var V=Z.split("-");if(2!==V.length)throw new Error("Bad session specification: "+z);var X=V[0],$=V[1];L.addSessionEntry(Q,H.get_minutes_from_hhmm(X),H.get_minutes_from_hhmm($))})})},b.prototype._parseFirstDayOfWeek=function(z){var L=z.split(";");if(2<L.length)throw new Error("Only one `first day` specification expected @ session "+z);if(1===L.length)return z;var J=0<=L[0].indexOf("-")?NaN:parseInt(L[0]),j=1;if(isNaN(J)&&(j=0,J=parseInt(L[1])),J<H.SUNDAY||J>H.SATURDAY)throw new Error("Unexpected day index @ session: "+z+"; day index "+J);return this._firstDayOfWeek=J,L[j]},b}();return function(b){return w(new I(b).entries())}}();
function displayResult() {
var session = document.querySelector('#session').value;
try {
var result = sessionFormatter(session);
var table;
if (result.length === 1) {
table = "<table><tr><td>" + result[0] + "</td></tr></table>";
} else {
table = "<table>" +
result.map(function(row, index) { return "<tr><td>" + index + "</td><td>" + row + "</td></tr>"; }).join('') +
"</table>";
}
document.querySelector('#result').innerHTML = table;
} catch (e) {
document.querySelector('#result').innerHTML = e.message;
}
return false;
}
</script>
<form class="table-fill">
<h1>Charting Library Session Parser</h1>
<input type="text" id="session" class="input-field" name="session" value="24x7" maxlength="500" oninput="displayResult();" autocomplete="off"/>
<div id="result" class="results"></div>
</form>
<script>
try {
var url = new URL(document.location.toString());
var session = url.searchParams.get("session");
if (session) {
document.querySelector("#session").value = session;
}
displayResult();
} catch(e) {
// URL not supported
}
</script>
</html>