Flex DateFormatter bug, missing January 1970 month name

Today, while working on a small piece of code I discovered something that appears to be a DateFormatter bug. I was using following DateFormatter:

private var formatter:DateFormatter = new DateFormatter();
...
 formatter.formatString = "MMMM";

to display just the month names. I didn’t really care about the year when constructing new Date so I thought I would pick 1970. It appears that for January 1970 the DateFormatter returns an empty string while for 1969, 1971 and any other dates it works fine. Here is the demo.

This movie requires Flash Player 9

And the source code below.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

 <mx:Script>
  <![CDATA[
   import mx.formatters.DateFormatter;

   [Bindable] private var names:String = "";
   private var formatter:DateFormatter = new DateFormatter();

   private function listMonths(year:Number):void {
    // get just the month name:
    formatter.formatString = "MMMM";
    // create dates and get formatted values:
    var values:Array = [];
    for ( var i:Number=0; i<12; i++ ) {
     values.push( formatter.format( new Date(year, i, 1) ) );
    }
    names = values.join(String.fromCharCode(13));
   }

  ]]>
 </mx:Script>

 <mx:HBox>
  <mx:Button label="1969" click="listMonths(1969);" />
  <mx:Button label="1970" click="listMonths(1970);" />
  <mx:Button label="1971" click="listMonths(1971);" />
 </mx:HBox>

 <mx:TextArea width="300" height="200" text="{names}" />

</mx:Application>

It appears that the bug was logged quite a few times, just one of the tickets I’ve found: https://bugs.adobe.com/jira/browse/SDK-14528. It also appears that it won’t be fixed. According to the comments under the linked story DateFormatter class is not an Adobe code. Interesting…

2 Responses to “Flex DateFormatter bug, missing January 1970 month name”

  1. Gregor Kiddie Says:

    The DateFormatter bug was fixed in the SDK 3.4 release recently.

  2. radekg Says:

    Good to know, thanks for info Gregor!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree