1 // ========================================================================== 2 // Project: SproutCore - JavaScript Application Framework 3 // Copyright: ©2006-2011 Strobe Inc. and contributors. 4 // Portions ©2008-2011 Apple Inc. All rights reserved. 5 // License: Licensed under MIT license (see license.js) 6 // ========================================================================== 7 8 SC.supplement(Number.prototype, { 9 10 /** 11 * Returns the ordinal associated for the current number: 12 * 13 * eg: 1 => 'st', 2 => 'nd' 14 * 15 * 16 * If the current Locale exists (which it almost always does except for in 17 * testing) we try and delegate to it. Otherwise we use this inner anonymous 18 * function (to prevent further mucking with the prototype) 19 * 20 */ 21 ordinal: function () { 22 // FAST PATH: If we have a localization, use its ordinals. 23 if (SC.Locale) { 24 return SC.Locale.currentLocale.ordinalForNumber(this); 25 } 26 27 // Otherwise, fall back on a basic (en) implementation (e.g. in testing, or as 28 // the datetime framework only requires the runtime framework). 29 var d = this % 10; 30 return (~~(this % 100 / 10) === 1) ? 'th' : 31 (d === 1) ? 'st' : 32 (d === 2) ? 'nd' : 33 (d === 3) ? 'rd' : 'th'; 34 } 35 36 });