1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 3<head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 5 <title>SyntaxHighlighter TypeScript Test</title> 6 <script type="text/javascript" src="../scripts/XRegExp.js"></script> 7 <script type="text/javascript" src="../scripts/shCore.js"></script> 8 <script type="text/javascript" src="../scripts/shBrushTypeScript.js"></script> 9 <link type="text/css" rel="stylesheet" href="../styles/shCore.css"/> 10 <link type="text/css" rel="Stylesheet" href="../styles/shThemeVisualStudio.css" /> 11 <script type="text/javascript">SyntaxHighlighter.all();</script> 12</head> 13 14<body> 15 16<h1>SyntaxHighlighter TypeScript Language Demo</h1> 17 18<script type="syntaxhighlighter" class="brush: typescript;"><![CDATA[ 19/// <reference path="exceptions.ts" /> 20 21declare function somethingElse(n: number, b:bool, s?: string, ...others: any[]); 22 23module Calendar { 24 25 /** Description of a non-working day of the week */ 26 export interface NonWorkingWeekDay { 27 28 /** The day in the week, 0 = sunday, 6 = saturday */ 29 day: number; 30 31 /** Description of why the day is not a working one */ 32 description: string; 33 34 } // interface NonWorkingWeekDay 35 36 /** Description of a non-working day of the year */ 37 export interface NonWorkingYearDay { 38 39 /** The day's month, 0 = january, 11 = december */ 40 month: number; 41 42 /** The day within the month, from 1 to 31 */ 43 day: number; 44 45 /** Description of why the day is not a working one */ 46 description: string; 47 48 } // interface NonWorkingYearDay 49 50 /** Global calendar */ 51 export class GlobalCalendar { 52 53 private workingDayStart = 9 * Hour; 54 private workingDayDuration = 8 * Hour; 55 private nonWorkingWeekDays: NonWorkingWeekDay[] = [ 56 { day: 0, description: "Sunday" }, 57 { day: 6, description: "Saturday" }, 58 ]; 59 private nonWorkingYearDays: NonWorkingYearDay[] = [ 60 { month: 11, day: 25, description: "Christmas" }, 61 ]; 62 private zeroTime = (new Date(2013, 0, 1)).getTime(); 63 64 get WorkingDayStart() { 65 return this.workingDayStart; 66 } // WorkingDayStart 67 68 get WorkingDayDuration() { 69 return this.workingDayDuration; 70 } // WorkingDayDuration 71 72 set WorkingDayDuration(val: number) { 73 this.workingDayDuration = val; 74 } // WorkingDayDuration 75 76 get WorkingDayEnd() { 77 return this.workingDayStart + this.workingDayDuration; 78 } // getWorkingDayEnd 79 80 private dateToOffsetPrimitive(date: Date, strict: bool) { 81 if (date === null) { 82 throw new ArgumentException("date"); 83 } 84 var dayStart = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime(); 85 var dayOffset = (date.getTime() - dayStart) - this.workingDayStart; 86 if (dayOffset < 0) { 87 if (strict) { 88 throw new ArgumentException("Invalid parameter 'date': time of day before the start of the working day"); 89 } 90 dayOffset = 0; 91 } 92 if (dayOffset >= this.workingDayDuration) { 93 if (strict) { 94 throw new ArgumentException("Invalid parameter 'date': time of day after the end of the working day"); 95 } 96 dayOffset = this.workingDayDuration - 1; 97 } 98 return Math.round((dayStart - this.zeroTime) / Day) * this.workingDayDuration + dayOffset; 99 } // dateToOffsetPrimitive 100 101 public dateToOffset(date: Date) { 102 return this.dateToOffsetPrimitive(date, false); 103 } // dateToOffset 104 105 public dateToOffsetStrict(date: Date) { 106 return this.dateToOffsetPrimitive(date, true); 107 } // dateToOffsetStrict 108 109 public dateFromOffset(offset: number) { 110 if (offset < 0) { 111 throw new ArgumentException("The parameter 'offset' cannot be negative"); 112 } 113 var days = Math.floor(offset / this.workingDayDuration); 114 var dayOffset = offset - days * this.workingDayDuration; 115 return new Date(this.zeroTime + days * Day + dayOffset + this.workingDayStart); 116 } // dateFromOffset 117 118 public isWorkingDay(date: Date) { 119 var dayOfWeek = date.getDay(); 120 for (var i = 0; i < this.nonWorkingWeekDays.length; i++) { 121 var nonWorkingWeekDay = this.nonWorkingWeekDays[i]; 122 if (nonWorkingWeekDay.day === dayOfWeek) { 123 return false; 124 } 125 } 126 var month = date.getMonth(); 127 var dayOfMonth = date.getDate(); 128 for (var i = 0; i < this.nonWorkingYearDays.length; i++) { 129 var nonWorkingYearDay = this.nonWorkingYearDays[i]; 130 if (nonWorkingYearDay.month === month && nonWorkingYearDay.day === dayOfMonth) { 131 return false; 132 } 133 } 134 return true; 135 } // isWorkingDay 136 137 } // class GlobalCalendar 138 139} // module Calendar 140]]></script> 141 142</body> 143</html> 144