r111373 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111372‎ | r111373 | r111374 >
Date:14:23, 13 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Reformat Date.replaceChars
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
@@ -161,10 +161,13 @@
162162
163163 // XXX: support localization
164164 Date.replaceChars = {
165 - shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
166 - longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
 165+ shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
 166+ 'Sep', 'Oct', 'Nov', 'Dec'],
 167+ longMonths: ['January', 'February', 'March', 'April', 'May', 'June',
 168+ 'July', 'August', 'September', 'October', 'November', 'December'],
167169 shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
168 - longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
 170+ longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
 171+ 'Friday', 'Saturday'],
169172
170173 // Day
171174 d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
@@ -172,43 +175,87 @@
173176 j: function() { return this.getDate(); },
174177 l: function() { return Date.replaceChars.longDays[this.getDay()]; },
175178 N: function() { return this.getDay() + 1; },
176 - S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
 179+ S: function() {
 180+ return (this.getDate() % 10 == 1 &&
 181+ this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 &&
 182+ this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 &&
 183+ this.getDate() != 13 ? 'rd' : 'th')));
 184+ },
177185 w: function() { return this.getDay(); },
178 - z: function() { var d = new Date(this.getFullYear(),0,1); return Math.ceil((this - d) / 86400000); }, // Fixed now
 186+ z: function() {
 187+ var d = new Date(this.getFullYear(),0,1);
 188+ return Math.ceil((this - d) / 86400000);
 189+ },
179190 // Week
180 - W: function() { var d = new Date(this.getFullYear(), 0, 1); return Math.ceil((((this - d) / 86400000) + d.getDay() + 1) / 7); }, // Fixed now
 191+ W: function() {
 192+ var d = new Date(this.getFullYear(), 0, 1);
 193+ return Math.ceil((((this - d) / 86400000) + d.getDay() + 1) / 7);
 194+ },
181195 // Month
182196 F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },
183197 m: function() { return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1); },
184198 M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },
185199 n: function() { return this.getMonth() + 1; },
186 - t: function() { var d = new Date(); return new Date(d.getFullYear(), d.getMonth(), 0).getDate(); }, // Fixed now, gets #days of date
 200+ t: function() {
 201+ var d = new Date();
 202+ return new Date(d.getFullYear(), d.getMonth(), 0).getDate();
 203+ },
187204 // Year
188 - L: function() { var year = this.getFullYear(); return (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)); }, // Fixed now
189 - o: function() { var d = new Date(this.valueOf()); d.setDate(d.getDate() - ((this.getDay() + 6) % 7) + 3); return d.getFullYear();}, //Fixed now
 205+ L: function() {
 206+ var year = this.getFullYear();
 207+ return (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0));
 208+ },
 209+ o: function() {
 210+ var d = new Date(this.valueOf());
 211+ d.setDate(d.getDate() - ((this.getDay() + 6) % 7) + 3);
 212+ return d.getFullYear();
 213+ },
190214 Y: function() { return this.getFullYear(); },
191215 y: function() { return ('' + this.getFullYear()).substr(2); },
192216 // Time
193217 a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
194218 A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
195 - B: function() { return Math.floor((((this.getUTCHours() + 1) % 24) + this.getUTCMinutes() / 60 + this.getUTCSeconds() / 3600) * 1000 / 24); }, // Fixed now
 219+ B: function() {
 220+ return Math.floor((((this.getUTCHours() + 1) % 24) +
 221+ this.getUTCMinutes() / 60 +
 222+ this.getUTCSeconds() / 3600) * 1000 / 24);
 223+ },
196224 g: function() { return this.getHours() % 12 || 12; },
197225 G: function() { return this.getHours(); },
198 - h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
 226+ h: function() {
 227+ return ((this.getHours() % 12 || 12) < 10 ? '0' : '') +
 228+ (this.getHours() % 12 || 12);
 229+ },
199230 H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
200231 i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
201232 s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
202 - u: function() { var m = this.getMilliseconds(); return (m < 10 ? '00' : (m < 100 ?
203 -'0' : '')) + m; },
 233+ u: function() {
 234+ var m = this.getMilliseconds();
 235+ return (m < 10 ? '00' : (m < 100 ? '0' : '')) + m;
 236+ },
204237 // Timezone
205238 e: function() { return "Not Yet Supported"; },
206239 I: function() { return "Not Yet Supported"; },
207 - O: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00'; },
208 - P: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + ':00'; }, // Fixed now
209 - T: function() { var m = this.getMonth(); this.setMonth(0); var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1'); this.setMonth(m); return result;},
 240+ O: function() {
 241+ return (-this.getTimezoneOffset() < 0 ? '-' : '+') +
 242+ (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') +
 243+ (Math.abs(this.getTimezoneOffset() / 60)) + '00';
 244+ },
 245+ P: function() {
 246+ return (-this.getTimezoneOffset() < 0 ? '-' : '+') +
 247+ (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') +
 248+ (Math.abs(this.getTimezoneOffset() / 60)) + ':00';
 249+ },
 250+ T: function() {
 251+ var m = this.getMonth();
 252+ this.setMonth(0);
 253+ var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1');
 254+ this.setMonth(m);
 255+ return result;
 256+ },
210257 Z: function() { return -this.getTimezoneOffset() * 60; },
211258 // Full Date/Time
212 - c: function() { return this.format("Y-m-d\\TH:i:sP"); }, // Fixed now
 259+ c: function() { return this.format("Y-m-d\\TH:i:sP"); },
213260 r: function() { return this.toString(); },
214261 U: function() { return this.getTime() / 1000; }
215262 };

Status & tagging log