forked from alexgorbatchev/syntaxhighlighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypescript_test.html
143 lines (115 loc) · 4.72 KB
/
typescript_test.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SyntaxHighlighter TypeScript Test</title>
<script type="text/javascript" src="../scripts/XRegExp.js"></script>
<script type="text/javascript" src="../scripts/shCore.js"></script>
<script type="text/javascript" src="../scripts/shBrushTypeScript.js"></script>
<link type="text/css" rel="stylesheet" href="../styles/shCore.css"/>
<link type="text/css" rel="Stylesheet" href="../styles/shThemeVisualStudio.css" />
<script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
<h1>SyntaxHighlighter TypeScript Language Demo</h1>
<script type="syntaxhighlighter" class="brush: typescript;"><![CDATA[
/// <reference path="exceptions.ts" />
declare function somethingElse(n: number, b:bool, s?: string, ...others: any[]);
module Calendar {
/** Description of a non-working day of the week */
export interface NonWorkingWeekDay {
/** The day in the week, 0 = sunday, 6 = saturday */
day: number;
/** Description of why the day is not a working one */
description: string;
} // interface NonWorkingWeekDay
/** Description of a non-working day of the year */
export interface NonWorkingYearDay {
/** The day's month, 0 = january, 11 = december */
month: number;
/** The day within the month, from 1 to 31 */
day: number;
/** Description of why the day is not a working one */
description: string;
} // interface NonWorkingYearDay
/** Global calendar */
export class GlobalCalendar {
private workingDayStart = 9 * Hour;
private workingDayDuration = 8 * Hour;
private nonWorkingWeekDays: NonWorkingWeekDay[] = [
{ day: 0, description: "Sunday" },
{ day: 6, description: "Saturday" },
];
private nonWorkingYearDays: NonWorkingYearDay[] = [
{ month: 11, day: 25, description: "Christmas" },
];
private zeroTime = (new Date(2013, 0, 1)).getTime();
get WorkingDayStart() {
return this.workingDayStart;
} // WorkingDayStart
get WorkingDayDuration() {
return this.workingDayDuration;
} // WorkingDayDuration
set WorkingDayDuration(val: number) {
this.workingDayDuration = val;
} // WorkingDayDuration
get WorkingDayEnd() {
return this.workingDayStart + this.workingDayDuration;
} // getWorkingDayEnd
private dateToOffsetPrimitive(date: Date, strict: bool) {
if (date === null) {
throw new ArgumentException("date");
}
var dayStart = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
var dayOffset = (date.getTime() - dayStart) - this.workingDayStart;
if (dayOffset < 0) {
if (strict) {
throw new ArgumentException("Invalid parameter 'date': time of day before the start of the working day");
}
dayOffset = 0;
}
if (dayOffset >= this.workingDayDuration) {
if (strict) {
throw new ArgumentException("Invalid parameter 'date': time of day after the end of the working day");
}
dayOffset = this.workingDayDuration - 1;
}
return Math.round((dayStart - this.zeroTime) / Day) * this.workingDayDuration + dayOffset;
} // dateToOffsetPrimitive
public dateToOffset(date: Date) {
return this.dateToOffsetPrimitive(date, false);
} // dateToOffset
public dateToOffsetStrict(date: Date) {
return this.dateToOffsetPrimitive(date, true);
} // dateToOffsetStrict
public dateFromOffset(offset: number) {
if (offset < 0) {
throw new ArgumentException("The parameter 'offset' cannot be negative");
}
var days = Math.floor(offset / this.workingDayDuration);
var dayOffset = offset - days * this.workingDayDuration;
return new Date(this.zeroTime + days * Day + dayOffset + this.workingDayStart);
} // dateFromOffset
public isWorkingDay(date: Date) {
var dayOfWeek = date.getDay();
for (var i = 0; i < this.nonWorkingWeekDays.length; i++) {
var nonWorkingWeekDay = this.nonWorkingWeekDays[i];
if (nonWorkingWeekDay.day === dayOfWeek) {
return false;
}
}
var month = date.getMonth();
var dayOfMonth = date.getDate();
for (var i = 0; i < this.nonWorkingYearDays.length; i++) {
var nonWorkingYearDay = this.nonWorkingYearDays[i];
if (nonWorkingYearDay.month === month && nonWorkingYearDay.day === dayOfMonth) {
return false;
}
}
return true;
} // isWorkingDay
} // class GlobalCalendar
} // module Calendar
]]></script>
</body>
</html>