Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Date Time formatting issue in Text/Dynamic Text
mstaniloiu
Hello,<br />
<br />
I am working on some BIRT reports which have the date time format for the whole report specified in themes defined in a rptlibrary (in the "report" style). This works for "Data" elements, but for "Dynamic Text" elements it doesn't seem to work correctly. Here is an example:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>"The report contains data starting from " + params["startDate"].value + " up to " + params["endDate"].value</pre>
<br />
No matter which date time format I specify in the theme, the parameters will have the format you can see below:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>The report contains data starting from Thu May 15 08:00:00 EEST 2008 up to Sat May 15 16:00:00 EEST 2010</pre>
<br />
On the other hand, the formatting works perfectly if I remove the text, leaving only the date time object:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>params["startDate"].value</pre>
<br />
What should I do so that the correct formatting is applied in both cases, not just the second?
Find more posts tagged with
Comments
mcremer
<blockquote class='ipsBlockquote' data-author="'mstaniloiu'" data-cid="84726" data-time="1320075664" data-date="31 October 2011 - 08:41 AM"><p>
Hello,<br />
<br />
I am working on some BIRT reports which have the date time format for the whole report specified in themes defined in a rptlibrary (in the "report" style). This works for "Data" elements, but for "Dynamic Text" elements it doesn't seem to work correctly. Here is an example:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>"The report contains data starting from " + params["startDate"].value + " up to " + params["endDate"].value</pre>
<br />
No matter which date time format I specify in the theme, the parameters will have the format you can see below:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>The report contains data starting from Thu May 15 08:00:00 EEST 2008 up to Sat May 15 16:00:00 EEST 2010</pre>
<br />
On the other hand, the formatting works perfectly if I remove the text, leaving only the date time object:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>params["startDate"].value</pre>
<br />
What should I do so that the correct formatting is applied in both cases, not just the second?<br /></p></blockquote>
<br />
Well this is becouse your casting your date to a string (ala Java).<br />
<br />
The formatter looks to the type of the field (eg String, etc). to see how to format it.<br />
<br />
If you want to format within the string you should script the formatting. On this topic I already posted example scripts: <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/23482-how-to-default-date-parameter-automatically-to-lastfirst-day-in-current-month/'>http://www.birt-exchange.org/org/forum/index.php/topic/23482-how-to-default-date-parameter-automatically-to-lastfirst-day-in-current-month/</a><br
/>
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/23005-changing-date-format/'>http://www.birt-exchange.org/org/forum/index.php/topic/23005-changing-date-format/</a><br
/>
<br />
Hope this helps.
mstaniloiu
<blockquote class='ipsBlockquote' data-author="'mcremer'" data-cid="84737" data-time="1320137343" data-date="01 November 2011 - 01:49 AM"><p>
Well this is becouse your casting your date to a string (ala Java).<br />
<br />
The formatter looks to the type of the field (eg String, etc). to see how to format it.<br />
<br />
If you want to format within the string you should script the formatting. On this topic I already posted example scripts: <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/23482-how-to-default-date-parameter-automatically-to-lastfirst-day-in-current-month/'>http://www.birt-exchange.org/org/forum/index.php/topic/23482-how-to-default-date-parameter-automatically-to-lastfirst-day-in-current-month/</a><br
/>
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/23005-changing-date-format/'>http://www.birt-exchange.org/org/forum/index.php/topic/23005-changing-date-format/</a><br
/>
<br />
Hope this helps.<br /></p></blockquote>
<br />
Unfortunately it's not so simple. I cannot hard-code the format within the javascript, as I only know it at runtime. I have two themes in my library, an EU theme and a US theme. I specify which theme should be used via a report parameter. For the EU theme the date-time format should be the following:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>d MMM y HH:mm:ss</pre>
<br />
And for the US theme:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>MMM d, y hh:mm:ss a</pre>
<br />
I could solve this problem if I could somehow define a format for each theme (having the same name) and then use it when defining the SimpleDateFormat in the javascript, but I don't know if that's possible.
mcremer
<blockquote class='ipsBlockquote' data-author="'mstaniloiu'" data-cid="84742" data-time="1320143022" data-date="01 November 2011 - 03:23 AM"><p>
Unfortunately it's not so simple. I cannot hard-code the format within the javascript, as I only know it at runtime. I have two themes in my library, an EU theme and a US theme. I specify which theme should be used via a report parameter. For the EU theme the date-time format should be the following:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>d MMM y HH:mm:ss</pre>
<br />
And for the US theme:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>MMM d, y hh:mm:ss a</pre>
<br />
I could solve this problem if I could somehow define a format for each theme (having the same name) and then use it when defining the SimpleDateFormat in the javascript, but I don't know if that's possible.<br /></p></blockquote>
<br />
You can use the parm as folows. (this is an example and realy rough this wont work but should show the logic)<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if (params["region"].value == 'US') {
-- Java has a bad neck to have standart American standarts.
nl_NL = new Packages.java.util.Locale("en","US");
dfd = new Packages.java.text.SimpleDateFormat("MM-yyyy",nl_NL);
dfd2 = new Packages.java.text.SimpleDateFormat("MMM-yyyy",nl_NL);
pd = dfd.parse(params["stringdate"].value)
dfd2.format(pd);;
}
if (params["region"].value == 'eu') {
-- Java has a bad neck to have standart American standarts.
nl_NL = new Packages.java.util.Locale("nl","NL");
dfd = new Packages.java.text.SimpleDateFormat("MM-yyyy",nl_NL);
dfd2 = new Packages.java.text.SimpleDateFormat("MMM-yyyy",nl_NL);
pd = dfd.parse(params["stringdate"].value)
dfd2.format(pd);;
}
</pre>