Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
DateTime formatting contains "A.M." instead of "AM"
keithpower
Hi all,
I'm getting an Unparseable date error due to the formatting of a DateTime series in a BIRT chart. For some reason the formatting is producing "A.M." and "P.M." instead of "AM" and "PM" so it can't be parsed by some JavaScript code I have for localising dates.
I've got a Date/Time x-axis in a chart and I'm using the Advanced Formatting and providing "dd/MM/yyyy hh:mm a" as the Pattern. The Preview panel displays:
09/12/2008 12:07 a.m.
I'm using the SimpleDateFormat Java class to parse these dates in JavaScript, with the following pattern: "dd/MM/yyyy hh:mm a" which fails with the dates I get from the chart. If I replace the "a.m." with "am" they parse successfully.
I'm using BIRT 2.2.1, Eclipse Designer plugin on Windows.
The problem doesn't arise on the Solaris server I'm deploying to (also BIRT 2.2.1).
Does anyone know why it's using "a.m." ? Anyone have a workaround other than replacing that string ?
Many thanks,
Keith
Find more posts tagged with
Comments
mwilliams
Hi Keith,
Can you post the code you're using to do this? Thanks.
keithpower
Hi Michael,
Thanks for the reply. You can reproduce the cause of the problem without code, it's visible in the Chart editor window. If you add a chart with an x-axis of type Date/Time and then edit the formatting for the x-axis labels using Advanced Formatting and providing "dd/MM/yyyy hh:mm a" as the Pattern, on my machine the Preview panel displays:
09/12/2008 12:07 a.m.
I'll provide some code to demonstrate why this is a problem. I'm using the Java SimpleDateFormat class, so I'll provide some Java snippets if that's acceptable. In the report I call this class from JavaScript, but the error is identical.
This works:
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
sdf.applyPattern("MM/dd/yyyy hh:mm a");
System.out.println(sdf.format(sdf.parse("01/12/2008 12:00 am")));
but this doesn't because of the a.m.:
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
sdf.applyPattern("MM/dd/yyyy hh:mm a");
System.out.println(sdf.format(sdf.parse("01/12/2008 12:00 a.m.")));
It throws: java.text.ParseException: Unparseable date: "01/12/2008 12:00 a.m."
I've checked the docs and source for SimpleDateFormat and some other date formatting classes and a.m. doesn't seem to be supported by any of them.
I've also tested the above code in a couple of different Locales to see if that would make a difference. It didn't.
Any help would be much appreciated.
cheers,
Keith
keithpower
Here's a little more information to confuse or clarify the issue:
A colleague of mine is working with the same reports, but he's using the RCP Designer, version 2.2.1. When he attempts to recreate the issue the preview pane shows "AM" and not the "a.m." that's in mine...
cheers,
Keith
keithpower
From further investigation I believe the problem is with the ICU library.
That library (at least the version I have) adds a.m. and parses a.m. This works:
com.ibm.icu.text.SimpleDateFormat si = new com.ibm.icu.text.SimpleDateFormat( "dd/MM/yyyy hh:mm a");
si.applyPattern("MM/dd/yyyy hh:mm a");
System.out.println(si.format(si.parse("01/12/2008 12:00 a.m.")));
and produces:
01/12/2008 12:00 a.m.
It fails to parse the same date with "am" in place of "a.m.".
I still don't see how this is happening though. I've the same icu jar as my colleague and the server I'm deploying:
com.ibm.icu_3.6.1.v20070906.jar
cheers,
Keith