diff options
Diffstat (limited to 'bandwagon/content/scripts/util.js')
-rw-r--r-- | bandwagon/content/scripts/util.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/bandwagon/content/scripts/util.js b/bandwagon/content/scripts/util.js index 9dde8bb..8044f31 100644 --- a/bandwagon/content/scripts/util.js +++ b/bandwagon/content/scripts/util.js @@ -249,3 +249,47 @@ Bandwagon.Util.getInstalledExtensions = function() return items; } +Bandwagon.Util.ISO8601toDate = function(dString) +{ + var x = new Date(); + + var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/; + + if (dString.toString().match(new RegExp(regexp))) { + var d = dString.match(new RegExp(regexp)); + var offset = 0; + + x.setUTCDate(1); + x.setUTCFullYear(parseInt(d[1],10)); + x.setUTCMonth(parseInt(d[3],10) - 1); + x.setUTCDate(parseInt(d[5],10)); + x.setUTCHours(parseInt(d[7],10)); + x.setUTCMinutes(parseInt(d[9],10)); + x.setUTCSeconds(parseInt(d[11],10)); + if (d[12]) + x.setUTCMilliseconds(parseFloat(d[12]) * 1000); + else + x.setUTCMilliseconds(0); + if (d[13] != 'Z') { + offset = (d[15] * 60) + parseInt(d[17],10); + offset *= ((d[14] == '-') ? -1 : 1); + x.setTime(x.getTime() - offset * 60 * 1000); + } + } + else + { + x.setTime(Date.parse(dString)); + } + + return x; +}; + +Bandwagon.Util.getBrowserLocale = function() +{ + var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefService); + + return prefSvc.getCharPref("general.useragent.locale"); +}; + + |