[ https://issues.apache.org/jira/browse/FLEX-20017?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Justin Mclean resolved FLEX-20017. ---------------------------------- Resolution: Not A Problem Month values go from 0 to 11 not 1 to 12. Issue in sample code not Apache Flex SDK. > DateFormatter MMM & MMMM return month of by 1 > --------------------------------------------- > > Key: FLEX-20017 > URL: https://issues.apache.org/jira/browse/FLEX-20017 > Project: Apache Flex > Issue Type: Bug > Components: Formatters > Affects Versions: Adobe Flex SDK 3.2 (Release) > Environment: Affected OS(s): All OS Platforms > Affected OS(s): All OS Platforms > Language Found: English > Reporter: Adobe JIRA > Assignee: Justin Mclean > Labels: easyfix, easytest > > var df:DateFormatter = new DateFormatter(); > df.formatString = "DD MMM YY" > trace(df.format(new Date(2000,1,1))) > You get 01 Feb 00 when you should get 01 Jan 00 > The problem is in DateBase.extractTokenDate() > It looks up DateBase.monthNamesShort|monthNamesLong[month] when month is 1 > based, not zero based like the array. > The case where (key < 3) realises this, and does month++ > I'm using the Eclipse Plugin on MacOS. > This patch fixes it (use it in place of DateFormatter) > package > { > import mx.formatters.DateFormatter; > import mx.core.mx_internal; > import mx.managers.ISystemManager; > import mx.managers.SystemManager; > import mx.formatters.DateBase; > import mx.formatters.StringFormatter; > > public class DateFormatterPatched extends DateFormatter > { > > private static const VALID_PATTERN_CHARS:String = > "Y,M,D,A,E,H,J,K,L,N,S"; > > public function DateFormatterPatched() > { > super(); > } > > mx_internal static function extractTokenDate(date:Date, > > tokenInfo:Object):String > { > //initialize(); > //var result:String = ""; > > var key:int = int(tokenInfo.end) - int(tokenInfo.begin); > > //var day:int; > //var hours:int; > > switch (tokenInfo.token) { > case "M": > { > // month in year > var month:int = int(date.getMonth()); > if (key < 3) > { > return > DateBase.mx_internal::extractTokenDate(date,tokenInfo) > > } > else if (key == 3) > { > return > DateBase.monthNamesShort[month-1]; > } > else > { > return DateBase.monthNamesLong[month-1]; > } > } > } > return DateBase.mx_internal::extractTokenDate(date,tokenInfo) > } > > override public function format(value:Object):String > { > // Reset any previous errors. > if (error) > error = null; > // If value is null, or empty String just return "" > // but treat it as an error for consistency. > // Users will ignore it anyway. > if (!value || value == "") > { > error = defaultInvalidValueError; > return ""; > } > // -- value -- > if (value is String) > { > value = DateFormatter.parseDateString(String(value)); > if (!value) > { > error = defaultInvalidValueError; > return ""; > } > } > else if (!(value is Date)) > { > error = defaultInvalidValueError; > return ""; > } > // -- format -- > var letter:String; > var nTokens:int = 0; > var tokens:String = ""; > > var n:int = formatString.length; > for (var i:int = 0; i < n; i++) > { > letter = formatString.charAt(i); > if (VALID_PATTERN_CHARS.indexOf(letter) != -1 && letter != ",") > { > nTokens++; > if (tokens.indexOf(letter) == -1) > { > tokens += letter; > } > else > { > if (letter != formatString.charAt(Math.max(i - 1, 0))) > { > error = defaultInvalidFormatError; > return ""; > } > } > } > } > if (nTokens < 1) > { > error = defaultInvalidFormatError; > return ""; > } > var dataFormatter:StringFormatter = new StringFormatter( > formatString, VALID_PATTERN_CHARS, > DateFormatterPatched.mx_internal::extractTokenDate); > //DateBase.mx_internal::extractTokenDate); > return dataFormatter.formatValue(value); > } > } > } -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira