PageRenderTime 38ms CodeModel.GetById 11ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/aspnet_client/system_web/2_0_50727/CrystalReportWebFormViewer3/js/dt_param.js

http://github.com/khaneh/Orders
JavaScript | 344 lines | 287 code | 38 blank | 19 comment | 100 complexity | 71ac9b6c88fa81176655bae72795fb4d MD5 | raw file
  1
  2// TDC is to get DateTime format info for current locale
  3function TDC() { 
  4  var d=new Date(1970,0,0,0,0,0,0),d2=new Date(d),s1,s2,api=-1; 
  5  d.setHours(10); d2.setHours(11); 
  6  s1=d.toLocaleString(); s2=d2.toLocaleString(); 
  7  this.displayHour=(s1!=s2); 
  8  d.setHours(0); d2.setHours(0); 
  9  d.setMinutes(10); d2.setMinutes(11); 
 10  this.displayMinute=(d.toLocaleString()!=d2.toLocaleString()); 
 11  d.setMinutes(0); d2.setMinutes(0); 
 12  d.setSeconds(10); d2.setSeconds(11); 
 13  this.displaySecond=(d.toLocaleString()!=d2.toLocaleString()); 
 14  d.setSeconds(0); d2.setSeconds(0); 
 15  if (this.displayHour) { 
 16    for (i=0; i<((s1.length<s2.length)?s1.length:s2.length); i++) { 
 17      if (s1.charAt(i)!=s2.charAt(i)) { 
 18        api=i-1; break; 
 19      } 
 20    } 
 21    d.setHours(11); d2.setHours(23); 
 22    s1=d.toLocaleString(); s2=d2.toLocaleString(); 
 23    this.twelveHourClock=(s1.substring(api,api+2)==s2.substring(api,api+2)); 
 24    this.displayAMPM=(s1!=s2); 
 25    d.setHours(0); d2.setHours(0); 
 26    d.setHours(9); d2.setHours(11); 
 27    this.hourLeadZero=(d.toLocaleString().length==d2.toLocaleString().length); 
 28    d.setHours(0); d2.setHours(0); 
 29  } else { 
 30    this.twelveHourClock=false; 
 31    this.displayAMPM=false; 
 32    this.hourLeadZero=false; 
 33  } 
 34  if (this.displayMinute) { 
 35    d.setMinutes(9); d2.setMinutes(11); 
 36    this.minuteLeadZero=(d.toLocaleString().length==d2.toLocaleString().length); 
 37    d.setMinutes(0); d2.setMinutes(0); 
 38  } else 
 39    this.minuteLeadZero=false; 
 40  if (this.displaySecond) { 
 41    d.setSeconds(9); d2.setSeconds(11); 
 42    this.secondLeadZero=(d.toLocaleString().length==d2.toLocaleString().length); 
 43    d.setSeconds(0); d2.setSeconds(0); 
 44  } else 
 45    this.secondLeadZero=false; 
 46} 
 47
 48var TD = new TDC(); 
 49
 50// create time editables, hour dropdown, minute dropdown, second dropdown, and am/pm dropdown
 51function CreateTimeEditables(paramName, postFix, enabled, cssClass, style, hour, minute, second)
 52{
 53   var properties = "";
 54   if (!enabled)
 55   {
 56      properties += " disabled='disabled' ";
 57   }
 58      
 59   if (cssClass.length != 0)
 60   {
 61	 properties += " class='";
 62	 properties += cssClass;
 63	 properties += "' ";
 64   }
 65      
 66   if (style.length != 0)
 67   {
 68     properties += " style='";
 69     properties += style;
 70     properties += "' ";
 71   }
 72     
 73   var time_sep_span = "";
 74   time_sep_span += "<span ";
 75   time_sep_span += properties;
 76   time_sep_span += ">";
 77   time_sep_span += L_TIME_SEPARATOR;
 78   time_sep_span += "</span>";
 79
 80   var editablesHtml = "";
 81   if (TD.displayHour)
 82   {
 83      editablesHtml +=  "<SELECT ";
 84      editablesHtml += properties;      
 85      editablesHtml +=  " name='";
 86      editablesHtml += paramName;
 87      editablesHtml += postFix;
 88      editablesHtml += "Hour'>";
 89      
 90      var minHour;
 91      var maxHour;
 92      if (TD.twelveHourClock)
 93      {
 94         minHour = 1;
 95         maxHour = 12;
 96      }
 97      else
 98      {
 99         minHour = 0;
100         maxHour = 23;
101      }
102 
103      for (i = minHour; i <= maxHour ; i++){
104	      editablesHtml += " <option value='";
105          editablesHtml += i;
106          editablesHtml += "'";
107
108          if (!TD.twelveHourClock)
109	  {  
110	     if (i == hour)
111	     	editablesHtml += " selected ";
112          }
113          else
114          {
115	     if (( hour == 0) && (i == 12))  
116 		editablesHtml += " selected ";
117             else if ((hour == 12) && (i == 12))
118		editablesHtml += " selected ";
119             else if ((hour > 12) && (i == hour - 12))
120		editablesHtml += " selected ";
121	     else if (i == hour)
122                editablesHtml += " selected ";
123          }
124
125          if ((i < 10) && (TD.hourLeadZero))
126          {
127             editablesHtml += "> 0";
128          }
129          else
130	  {
131             editablesHtml += "> ";
132             
133          }
134          editablesHtml += i;
135          editablesHtml += "</option>\n";
136      }
137       
138      editablesHtml +=  "        </SELECT>";
139   }
140
141   if (TD.displayMinute)
142   {
143      if (editablesHtml.length != 0) 
144      {
145         editablesHtml += time_sep_span;
146      }
147 
148      editablesHtml += "<SELECT  ";
149      editablesHtml += properties;	   
150      editablesHtml += " name='";
151      editablesHtml += paramName;
152      editablesHtml += postFix;
153      editablesHtml += "Minute'>";
154      
155 
156      for (i = 0; i <= 59; i++){
157	      editablesHtml += " <option value='";
158          editablesHtml += i;
159          editablesHtml += "'";
160
161          if (i == minute)
162	         editablesHtml += " selected ";
163          if ((i < 10) && (TD.minuteLeadZero))
164          {
165             
166             editablesHtml += "> 0";
167             
168          }
169          else
170          {
171             editablesHtml += "> ";
172          }
173          editablesHtml += i;
174          editablesHtml += "</option>\n";
175      }
176       
177      editablesHtml +=  "        </SELECT>";
178   }
179 
180   if (TD.displaySecond)
181   {
182      if (editablesHtml.length != 0)
183         editablesHtml += time_sep_span;
184      
185      editablesHtml += "<SELECT ";
186      editablesHtml += properties;  
187      editablesHtml += " name='";
188      editablesHtml += paramName;
189      editablesHtml += postFix;
190      editablesHtml += "Second'>";
191      
192 
193      for (i = 0; i <= 59; i++){
194          editablesHtml += " <option value='";
195          editablesHtml += i;
196	      editablesHtml += "'";
197 
198          if (i == second)
199	         editablesHtml += " selected ";
200
201          if ((i < 10) && (TD.secondLeadZero))
202             editablesHtml += "> 0";
203          else
204             editablesHtml += "> ";;
205          editablesHtml += i;
206          editablesHtml += "</option>\n";
207      }
208       
209      editablesHtml +=  "        </SELECT>";
210   }
211   
212   if (TD.twelveHourClock)
213   {
214      editablesHtml +=  "<SELECT ";
215      editablesHtml += properties;
216      editablesHtml += " name='";
217      editablesHtml += paramName;
218      editablesHtml += postFix;
219      editablesHtml += "AMPM' >";
220      editablesHtml += " <option value='0'";
221      if (hour < 12)
222	    editablesHtml += " selected ";
223      editablesHtml += "> ";
224      editablesHtml += L_AM_DESIGNATOR;
225      editablesHtml += "</option>\n";
226      editablesHtml += " <option value='1'"; 
227      if (hour >= 12)
228	    editablesHtml += " selected ";
229      editablesHtml += "> ";
230      editablesHtml += L_PM_DESIGNATOR;
231      editablesHtml += "</option>\n";
232      editablesHtml +=  "        </SELECT>";
233   }
234  
235   return editablesHtml;
236}
237
238// get Locale Date/Time
239// d: input Date
240// return only Date part if includeDate==true, and includeTime== false
241// return only Time part if includeDate==false and includeTime== true
242// return datetime string if includeDate==true and includeTime == true
243function GLDT(d, includeDate, includeTime) { // Get Locale Date/Time 
244  // Returns date/and or time from locale string. 
245  // Assumes that date appears before time in string. 
246  if (includeDate && includeTime) return d.toLocaleString(); 
247
248  var d2 = new Date(d);
249  var ds;
250  var ds2;
251  var ml; 
252  d2.setMilliseconds(d.getMilliseconds()<=887 ? d.getMilliseconds()+111 : d.getMilliseconds() - 111); 
253  d2.setSeconds(d.getSeconds()<=49 ? d.getSeconds()+11 : d.getSeconds()-11); 
254  d2.setMinutes(d.getMinutes()<=49 ? d.getMinutes()+11 : d.getMinutes()-11); 
255  
256  // although TD.twelveHourClock could be true, but d.getHours will always get hours in 24
257  // only the localized the date string will be in twelve hour clock
258  // here we want d2's hour's first digit different from d1's hour's first digit
259  // also if d1 is morning, d2 will be in afternoon, vice versa thus we get different strings for AM, and PM
260  // because AM/PM could be before hours (eg. in Korean)
261  if (TD.twelveHourClock) 
262  {
263	var hour = d.getHours();
264	if (hour == 0 || hour == 1 || hour == 10 || hour == 11)
265	{
266		d2.setHours(14);
267	} 
268	else if (hour == 12 || hour == 13 || hour == 22 || hour == 23)
269	{
270		d2.setHours(2);
271	}
272	else if (hour < 12)
273	{
274		d2.setHours(13);
275	}
276	else 
277	{
278		d2.setHours(1);
279	}
280  }
281  else 
282  { 
283    d2.setHours( d.getHours()<12 ? (d.getHours() == 1 ? 2 : d.getHours() + 12) : (d.getHours()<20 ? 20 : 11)); 
284  } 
285    
286  ds = d.toLocaleString(); 
287
288  ds2 = d2.toLocaleString(); 
289
290  ml = ds.length < ds2.length ? ds.length : ds2.length ;
291  for (i=0; i<ml; i++) { 
292    if (ds.charAt(i) != ds2.charAt(i)) 
293	{
294		// put the iterator back to the beginning of the word
295		while (ds.charAt(i) != ' ') i--;
296		i++;
297		break;
298	}
299  } 
300  if (includeDate) 
301    return ds.substring(0, i-1);
302  else if (includeTime) 
303    return ds.substring(i); 
304  else 
305    return ""; 
306} 
307
308// construct localized datetime/date/time string 
309// from DateTime(year, month, day, hour, minute, second)
310// or   Date(year, month, day)
311// or   Time(hour, minute, second)
312function NeutralDT2D(s) { 
313  var d="";
314  var td = new Date();
315  var a; 
316  if (s.indexOf("DateTime")!=-1) { 
317    a = s.replace("DateTime","").replace("(","").replace(")","").split(",") ;
318    d = GLDT(new Date(a[0], a[1]-1, a[2], a[3], a[4], a[5], 0), true, true); 
319  } else if (s.indexOf("Date")!=-1) { 
320    a = s.replace("Date","").replace("(","").replace(")","").split(",") ;
321    d = GLDT(new Date(a[0], a[1]-1, a[2], 0, 0, 0, 0), true, false); 
322  } else if (s.indexOf("Time")!=-1) { 
323    a = s.replace("Time","").replace("(","").replace(")","").split(","); 
324    d = GLDT(new Date(td.getYear(), td.getMonth(), td.getDate(), a[0], a[1], a[2]), false, true); 
325  }
326  return d; 
327}
328
329function NeutralDT2Date(s){
330  var d="";
331  var td = new Date();
332  var a; 
333  if (s.indexOf("DateTime")!=-1) { 
334    a = s.replace("DateTime","").replace("(","").replace(")","").split(",") ;
335    return new Date(a[0], a[1]-1, a[2], a[3], a[4], a[5], 0);
336  } else if (s.indexOf("Date")!=-1) { 
337    a = s.replace("Date","").replace("(","").replace(")","").split(",") ;
338    return new Date(a[0], a[1]-1, a[2], 0, 0, 0, 0);
339  } else if (s.indexOf("Time")!=-1) { 
340    a = s.replace("Time","").replace("(","").replace(")","").split(","); 
341    return new Date(td.getYear(), td.getMonth(), td.getDate(), a[0], a[1], a[2]);
342  }
343  return d; 
344}