Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /*** |
michael@0 | 2 | |
michael@0 | 3 | MochiKit.DateTime 1.4.2 |
michael@0 | 4 | |
michael@0 | 5 | See <http://mochikit.com/> for documentation, downloads, license, etc. |
michael@0 | 6 | |
michael@0 | 7 | (c) 2005 Bob Ippolito. All rights Reserved. |
michael@0 | 8 | |
michael@0 | 9 | ***/ |
michael@0 | 10 | |
michael@0 | 11 | MochiKit.Base._deps('DateTime', ['Base']); |
michael@0 | 12 | |
michael@0 | 13 | MochiKit.DateTime.NAME = "MochiKit.DateTime"; |
michael@0 | 14 | MochiKit.DateTime.VERSION = "1.4.2"; |
michael@0 | 15 | MochiKit.DateTime.__repr__ = function () { |
michael@0 | 16 | return "[" + this.NAME + " " + this.VERSION + "]"; |
michael@0 | 17 | }; |
michael@0 | 18 | MochiKit.DateTime.toString = function () { |
michael@0 | 19 | return this.__repr__(); |
michael@0 | 20 | }; |
michael@0 | 21 | |
michael@0 | 22 | /** @id MochiKit.DateTime.isoDate */ |
michael@0 | 23 | MochiKit.DateTime.isoDate = function (str) { |
michael@0 | 24 | str = str + ""; |
michael@0 | 25 | if (typeof(str) != "string" || str.length === 0) { |
michael@0 | 26 | return null; |
michael@0 | 27 | } |
michael@0 | 28 | var iso = str.split('-'); |
michael@0 | 29 | if (iso.length === 0) { |
michael@0 | 30 | return null; |
michael@0 | 31 | } |
michael@0 | 32 | var date = new Date(iso[0], iso[1] - 1, iso[2]); |
michael@0 | 33 | date.setFullYear(iso[0]); |
michael@0 | 34 | date.setMonth(iso[1] - 1); |
michael@0 | 35 | date.setDate(iso[2]); |
michael@0 | 36 | return date; |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | MochiKit.DateTime._isoRegexp = /(\d{4,})(?:-(\d{1,2})(?:-(\d{1,2})(?:[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2})(?:\.(\d+))?)?(?:(Z)|([+-])(\d{1,2})(?::(\d{1,2}))?)?)?)?)?/; |
michael@0 | 40 | |
michael@0 | 41 | /** @id MochiKit.DateTime.isoTimestamp */ |
michael@0 | 42 | MochiKit.DateTime.isoTimestamp = function (str) { |
michael@0 | 43 | str = str + ""; |
michael@0 | 44 | if (typeof(str) != "string" || str.length === 0) { |
michael@0 | 45 | return null; |
michael@0 | 46 | } |
michael@0 | 47 | var res = str.match(MochiKit.DateTime._isoRegexp); |
michael@0 | 48 | if (typeof(res) == "undefined" || res === null) { |
michael@0 | 49 | return null; |
michael@0 | 50 | } |
michael@0 | 51 | var year, month, day, hour, min, sec, msec; |
michael@0 | 52 | year = parseInt(res[1], 10); |
michael@0 | 53 | if (typeof(res[2]) == "undefined" || res[2] === '') { |
michael@0 | 54 | return new Date(year); |
michael@0 | 55 | } |
michael@0 | 56 | month = parseInt(res[2], 10) - 1; |
michael@0 | 57 | day = parseInt(res[3], 10); |
michael@0 | 58 | if (typeof(res[4]) == "undefined" || res[4] === '') { |
michael@0 | 59 | return new Date(year, month, day); |
michael@0 | 60 | } |
michael@0 | 61 | hour = parseInt(res[4], 10); |
michael@0 | 62 | min = parseInt(res[5], 10); |
michael@0 | 63 | sec = (typeof(res[6]) != "undefined" && res[6] !== '') ? parseInt(res[6], 10) : 0; |
michael@0 | 64 | if (typeof(res[7]) != "undefined" && res[7] !== '') { |
michael@0 | 65 | msec = Math.round(1000.0 * parseFloat("0." + res[7])); |
michael@0 | 66 | } else { |
michael@0 | 67 | msec = 0; |
michael@0 | 68 | } |
michael@0 | 69 | if ((typeof(res[8]) == "undefined" || res[8] === '') && (typeof(res[9]) == "undefined" || res[9] === '')) { |
michael@0 | 70 | return new Date(year, month, day, hour, min, sec, msec); |
michael@0 | 71 | } |
michael@0 | 72 | var ofs; |
michael@0 | 73 | if (typeof(res[9]) != "undefined" && res[9] !== '') { |
michael@0 | 74 | ofs = parseInt(res[10], 10) * 3600000; |
michael@0 | 75 | if (typeof(res[11]) != "undefined" && res[11] !== '') { |
michael@0 | 76 | ofs += parseInt(res[11], 10) * 60000; |
michael@0 | 77 | } |
michael@0 | 78 | if (res[9] == "-") { |
michael@0 | 79 | ofs = -ofs; |
michael@0 | 80 | } |
michael@0 | 81 | } else { |
michael@0 | 82 | ofs = 0; |
michael@0 | 83 | } |
michael@0 | 84 | return new Date(Date.UTC(year, month, day, hour, min, sec, msec) - ofs); |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | /** @id MochiKit.DateTime.toISOTime */ |
michael@0 | 88 | MochiKit.DateTime.toISOTime = function (date, realISO/* = false */) { |
michael@0 | 89 | if (typeof(date) == "undefined" || date === null) { |
michael@0 | 90 | return null; |
michael@0 | 91 | } |
michael@0 | 92 | var hh = date.getHours(); |
michael@0 | 93 | var mm = date.getMinutes(); |
michael@0 | 94 | var ss = date.getSeconds(); |
michael@0 | 95 | var lst = [ |
michael@0 | 96 | ((realISO && (hh < 10)) ? "0" + hh : hh), |
michael@0 | 97 | ((mm < 10) ? "0" + mm : mm), |
michael@0 | 98 | ((ss < 10) ? "0" + ss : ss) |
michael@0 | 99 | ]; |
michael@0 | 100 | return lst.join(":"); |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | /** @id MochiKit.DateTime.toISOTimeStamp */ |
michael@0 | 104 | MochiKit.DateTime.toISOTimestamp = function (date, realISO/* = false*/) { |
michael@0 | 105 | if (typeof(date) == "undefined" || date === null) { |
michael@0 | 106 | return null; |
michael@0 | 107 | } |
michael@0 | 108 | var sep = realISO ? "T" : " "; |
michael@0 | 109 | var foot = realISO ? "Z" : ""; |
michael@0 | 110 | if (realISO) { |
michael@0 | 111 | date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000)); |
michael@0 | 112 | } |
michael@0 | 113 | return MochiKit.DateTime.toISODate(date) + sep + MochiKit.DateTime.toISOTime(date, realISO) + foot; |
michael@0 | 114 | }; |
michael@0 | 115 | |
michael@0 | 116 | /** @id MochiKit.DateTime.toISODate */ |
michael@0 | 117 | MochiKit.DateTime.toISODate = function (date) { |
michael@0 | 118 | if (typeof(date) == "undefined" || date === null) { |
michael@0 | 119 | return null; |
michael@0 | 120 | } |
michael@0 | 121 | var _padTwo = MochiKit.DateTime._padTwo; |
michael@0 | 122 | var _padFour = MochiKit.DateTime._padFour; |
michael@0 | 123 | return [ |
michael@0 | 124 | _padFour(date.getFullYear()), |
michael@0 | 125 | _padTwo(date.getMonth() + 1), |
michael@0 | 126 | _padTwo(date.getDate()) |
michael@0 | 127 | ].join("-"); |
michael@0 | 128 | }; |
michael@0 | 129 | |
michael@0 | 130 | /** @id MochiKit.DateTime.americanDate */ |
michael@0 | 131 | MochiKit.DateTime.americanDate = function (d) { |
michael@0 | 132 | d = d + ""; |
michael@0 | 133 | if (typeof(d) != "string" || d.length === 0) { |
michael@0 | 134 | return null; |
michael@0 | 135 | } |
michael@0 | 136 | var a = d.split('/'); |
michael@0 | 137 | return new Date(a[2], a[0] - 1, a[1]); |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | MochiKit.DateTime._padTwo = function (n) { |
michael@0 | 141 | return (n > 9) ? n : "0" + n; |
michael@0 | 142 | }; |
michael@0 | 143 | |
michael@0 | 144 | MochiKit.DateTime._padFour = function(n) { |
michael@0 | 145 | switch(n.toString().length) { |
michael@0 | 146 | case 1: return "000" + n; break; |
michael@0 | 147 | case 2: return "00" + n; break; |
michael@0 | 148 | case 3: return "0" + n; break; |
michael@0 | 149 | case 4: |
michael@0 | 150 | default: |
michael@0 | 151 | return n; |
michael@0 | 152 | } |
michael@0 | 153 | }; |
michael@0 | 154 | |
michael@0 | 155 | /** @id MochiKit.DateTime.toPaddedAmericanDate */ |
michael@0 | 156 | MochiKit.DateTime.toPaddedAmericanDate = function (d) { |
michael@0 | 157 | if (typeof(d) == "undefined" || d === null) { |
michael@0 | 158 | return null; |
michael@0 | 159 | } |
michael@0 | 160 | var _padTwo = MochiKit.DateTime._padTwo; |
michael@0 | 161 | return [ |
michael@0 | 162 | _padTwo(d.getMonth() + 1), |
michael@0 | 163 | _padTwo(d.getDate()), |
michael@0 | 164 | d.getFullYear() |
michael@0 | 165 | ].join('/'); |
michael@0 | 166 | }; |
michael@0 | 167 | |
michael@0 | 168 | /** @id MochiKit.DateTime.toAmericanDate */ |
michael@0 | 169 | MochiKit.DateTime.toAmericanDate = function (d) { |
michael@0 | 170 | if (typeof(d) == "undefined" || d === null) { |
michael@0 | 171 | return null; |
michael@0 | 172 | } |
michael@0 | 173 | return [d.getMonth() + 1, d.getDate(), d.getFullYear()].join('/'); |
michael@0 | 174 | }; |
michael@0 | 175 | |
michael@0 | 176 | MochiKit.DateTime.EXPORT = [ |
michael@0 | 177 | "isoDate", |
michael@0 | 178 | "isoTimestamp", |
michael@0 | 179 | "toISOTime", |
michael@0 | 180 | "toISOTimestamp", |
michael@0 | 181 | "toISODate", |
michael@0 | 182 | "americanDate", |
michael@0 | 183 | "toPaddedAmericanDate", |
michael@0 | 184 | "toAmericanDate" |
michael@0 | 185 | ]; |
michael@0 | 186 | |
michael@0 | 187 | MochiKit.DateTime.EXPORT_OK = []; |
michael@0 | 188 | MochiKit.DateTime.EXPORT_TAGS = { |
michael@0 | 189 | ":common": MochiKit.DateTime.EXPORT, |
michael@0 | 190 | ":all": MochiKit.DateTime.EXPORT |
michael@0 | 191 | }; |
michael@0 | 192 | |
michael@0 | 193 | MochiKit.DateTime.__new__ = function () { |
michael@0 | 194 | // MochiKit.Base.nameFunctions(this); |
michael@0 | 195 | var base = this.NAME + "."; |
michael@0 | 196 | for (var k in this) { |
michael@0 | 197 | var o = this[k]; |
michael@0 | 198 | if (typeof(o) == 'function' && typeof(o.NAME) == 'undefined') { |
michael@0 | 199 | try { |
michael@0 | 200 | o.NAME = base + k; |
michael@0 | 201 | } catch (e) { |
michael@0 | 202 | // pass |
michael@0 | 203 | } |
michael@0 | 204 | } |
michael@0 | 205 | } |
michael@0 | 206 | }; |
michael@0 | 207 | |
michael@0 | 208 | MochiKit.DateTime.__new__(); |
michael@0 | 209 | |
michael@0 | 210 | if (typeof(MochiKit.Base) != "undefined") { |
michael@0 | 211 | MochiKit.Base._exportSymbols(this, MochiKit.DateTime); |
michael@0 | 212 | } else { |
michael@0 | 213 | (function (globals, module) { |
michael@0 | 214 | if ((typeof(JSAN) == 'undefined' && typeof(dojo) == 'undefined') |
michael@0 | 215 | || (MochiKit.__export__ === false)) { |
michael@0 | 216 | var all = module.EXPORT_TAGS[":all"]; |
michael@0 | 217 | for (var i = 0; i < all.length; i++) { |
michael@0 | 218 | globals[all[i]] = module[all[i]]; |
michael@0 | 219 | } |
michael@0 | 220 | } |
michael@0 | 221 | })(this, MochiKit.DateTime); |
michael@0 | 222 | } |