|
1 // //////////////////////////////////////////////////////////////////////////// |
|
2 // Symbian Foundation Example Code |
|
3 // |
|
4 // This software is in the public domain. No copyright is claimed, and you |
|
5 // may use it for any purpose without license from the Symbian Foundation. |
|
6 // No warranty for any purpose is expressed or implied by the authors or |
|
7 // the Symbian Foundation. |
|
8 // //////////////////////////////////////////////////////////////////////////// |
|
9 |
|
10 // Session class is used to encapsulate all session data |
|
11 function Session(){ |
|
12 this.date = null; |
|
13 this.location = null; |
|
14 this.startTime = null; |
|
15 this.endTime = null; |
|
16 this.topic = null; |
|
17 this.chair = null; |
|
18 this.speakers = null; |
|
19 this.title = null; |
|
20 this.description = null; |
|
21 } |
|
22 |
|
23 Session.prototype.GetContentHTML = function () { |
|
24 var buf = "<small><i>" + this.startTime + " - " + this.endTime; |
|
25 if ( this.location ) { |
|
26 buf += ", " + this.location; |
|
27 } |
|
28 buf += "</i>"; |
|
29 var haschair = false; |
|
30 if ( this.chair && this.chair != null && this.chair.length > 0 ) { |
|
31 var ch = this.chair.replace(/<br>/g, ", "); |
|
32 buf += "<br><b>Chair: " + ch + "</b>"; |
|
33 haschair = true; |
|
34 } |
|
35 if (this.speakers && this.speakers != null && this.speakers.length > 0) { |
|
36 buf += "<b>, " |
|
37 if ( haschair ) { |
|
38 buf += "Speakers: "; |
|
39 } |
|
40 // remove nasty newlines |
|
41 var spk = this.speakers.replace(/<br>/g, ", "); |
|
42 buf += spk + "</b>"; |
|
43 } |
|
44 buf += "<br>" + this.description + "</small>"; |
|
45 return buf; |
|
46 } |
|
47 |
|
48 |
|
49 // Used when parsing to assign a value by ordinal |
|
50 Session.prototype.SetFieldByOrdinal = function(ordinal, val) { |
|
51 switch(ordinal) { |
|
52 case 0: this.date = val; break; |
|
53 case 1: this.location = val; break; |
|
54 case 2: this.startTime = val; break; |
|
55 case 3: this.endTime = val; break; |
|
56 case 4: this.topic = val; break; |
|
57 case 5: this.chair = val; break; |
|
58 case 6: this.speakers = val; break; |
|
59 case 7: this.title = val; break; |
|
60 case 8: this.description = val; break; |
|
61 } |
|
62 } |
|
63 |
|
64 Session.prototype.GetNumberOfFields = function () { |
|
65 return 9; |
|
66 } |
|
67 |
|
68 Session.prototype.GetStartUtc = function(){ |
|
69 return this.GetUtcTime(this.date, this.startTime); |
|
70 } |
|
71 |
|
72 Session.prototype.GetEndUtc = function(){ |
|
73 return this.GetUtcTime(this.date, this.endTime); |
|
74 } |
|
75 |
|
76 Session.prototype.GetUtcTime = function(dateString, timeString){ |
|
77 // make a date, then we'll mod it |
|
78 var d = new Date(); |
|
79 // dateString is in the format DD-mmm-YY |
|
80 var parts = dateString.split("-"); |
|
81 d.setFullYear(parseInt(parts[2]) + 2000); |
|
82 d.setDate(parseInt(parts[0])); |
|
83 d.setMonth(indexOfMonth(parts[1])); |
|
84 // time is in the format HH:MM |
|
85 parts = timeString.split(":"); |
|
86 d.setHours(parseInt(parts[0])); |
|
87 d.setMinutes(parseInt(parts[1])); |
|
88 // convert to msec since Jan 1 1970 |
|
89 var localTime = d.getTime(); |
|
90 // obtain local UTC offset and convert to msec |
|
91 var localOffset = d.getTimezoneOffset() * 60000; |
|
92 // obtain UTC time in msec |
|
93 return localTime + localOffset; |
|
94 } |
|
95 |
|
96 function indexOfMonth(m){ |
|
97 switch(m.toLowerCase()) { |
|
98 case "jan": return 1; |
|
99 case "feb": return 2; |
|
100 case "mar": return 3; |
|
101 case "apr": return 4; |
|
102 case "may": return 5; |
|
103 case "jun": return 6; |
|
104 case "jul": return 7; |
|
105 case "aug": return 8; |
|
106 case "sep": return 9; |
|
107 case "oct": return 10; |
|
108 case "nov": return 11; |
|
109 case "dec": return 12; |
|
110 } |
|
111 } |