PageRenderTime 33ms CodeModel.GetById 13ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/org/apache/struts2/static/dputils.js

http://struts2yuiplugin.googlecode.com/
JavaScript | 58 lines | 53 code | 5 blank | 0 comment | 10 complexity | e59fb63215fdb32af27126950645a4d7 MD5 | raw file
 1var s2yui = YAHOO.namespace("s2yui");
 2YAHOO.namespace("s2yui.i18n");
 3
 4YAHOO.s2yui.toRFC3339 = function(dateObject) {
 5  if(!dateObject){
 6    dateObject = new Date();
 7  }
 8  var formattedDate = [];
 9  var date = [this.padString(dateObject.getFullYear(),4), this.padString(dateObject.getMonth()+1,2), this.padString(dateObject.getDate(),2)].join('-');
10  formattedDate.push(date);
11  
12  var time = [this.padString(dateObject.getHours(),2), this.padString(dateObject.getMinutes(),2), this.padString(dateObject.getSeconds(),2)].join(':');
13  var timezoneOffset = dateObject.getTimezoneOffset();
14  time += (timezoneOffset > 0 ? "-" : "+") + 
15          this.padString(Math.floor(Math.abs(timezoneOffset)/60),2) + ":" +
16          this.padString(Math.abs(timezoneOffset)%60,2);
17  formattedDate.push(time);
18  return formattedDate.join('T'); // String
19};
20
21YAHOO.s2yui.padString = function (str, len, c, dir) {
22 var out = String(str);
23  if(!c) {
24    c = '0';
25  }
26  if(!dir) {
27    dir = 1;
28  }
29  while(out.length < len) {
30    if(dir > 0) {
31      out = c + out;
32    } else {
33      out += c;
34    }
35  }
36  return out;  //  string
37};
38
39YAHOO.s2yui.showDateValue = function(target, value) {
40  if(target.nodeName.toLowerCase() == "input") {
41    target.value = value;
42  } else {
43    target.innerHTML = value;
44  }
45};
46
47YAHOO.s2yui.loadLanguageStrings = function(dp, langName) {
48  var lang = YAHOO.s2yui.i18n[langName];
49  if(!lang) {
50    YAHOO.log("Language " + langName + " is not available");
51    return;
52  } else {
53    dp.cfg.setProperty("MONTHS_SHORT", lang.months_short);
54    dp.cfg.setProperty("MONTHS_LONG", lang.months_long);
55    dp.cfg.setProperty("WEEKDAYS_SHORT", lang.weekdays_short);
56    dp.cfg.setProperty("WEEKDAYS_LONG", lang.weekdays_long );
57  }
58};