Home
Analytics
Problem with the diffmin function when I have different time zone
fannyV
<p>Hi, </p>
<p> </p>
<p>I'm tring to understand something with the datetime. </p>
<p> </p>
<p>I'm using a date in the database, i received the good date in the data binding. But I need to have the difference between now and the date in my record. </p>
<p> </p>
<p>My data is on one french server (for example) and I'm at Hawaii or Alaska [I changed the time zone]. I didn't receive the same minutes. [hawaii : 30 min more and Alaska : 59 min more]. </p>
<p> </p>
<p>To understand what I did : </p>
<p>I create one date : </p>
<pre class="_prettyXprint">
var dateOne = new Date();</pre>
<p>and the second with my data : </p>
<pre class="_prettyXprint">
var dateTwo = new Date(dataSetRow["column"]);</pre>
<p>and I try to take the difference minutes : </p>
<pre class="_prettyXprint">
var mins = BirtDateTime.diffMinute(dateOne, dateTwo);</pre>
<p> I tried to change the web.xml : </p>
<pre class="_prettyXprint _lang-">
<!--
Default timezone setting.
Examples: "Europe/Paris", "GMT+1".
Defaults to the container's timezone.
-->
<context-param>
<param-name>BIRT_VIEWER_TIMEZONE</param-name>
<param-value></param-value>
</context-param>
</pre>
<p>with the <param-value></param-value> GTM+1 but it didn't work. </p>
<p> </p>
<p>Could you help me to "force" the new date to take the french time zone (or another one)? </p>
<p> </p>
<p>Thanks,</p>
Find more posts tagged with
Comments
fannyV
<p>any idea? </p>
shamo
<p>Just use Birtdatetime.diffMinute(datefield,Birtdatetime.now())</p>
fannyV
<p>Hi Shamo,</p>
<p>Thanks for your help.</p>
<p> </p>
<p>I've the same problem with BirtDateTime.now().</p>
<p>I took a look on Internet and found : <a data-ipb='nomediaparse' href='
https://www.eclipse.org/forums/index.php/t/1065349/'>https://www.eclipse.org/forums/index.php/t/1065349/</a></p>
;
<p> </p>
<p>I don't know if I can find a workaround. Is it a known issue? Did Birt fix it in a earlier version? </p>
Clement Wong
<p>To better assist you, I would like to understand your environment...</p>
<p> </p>
<p>1. Are you using Open Source BIRT, or commercial BIRT? What version?</p>
<p>2. What timezone is set your database machine ?</p>
<p>3. Can you provide one sample value it is returning?</p>
<p>4. What timezone is set on your Application Server (if running OS BIRT), or iHub (if running commercial BIRT) machine?</p>
<p>5. Can you provide sample values of what you are expecting?</p>
<p> </p>
<p>BIRT uses the timezone as defined in the JRE.</p>
fannyV
<p>Hi Clement, </p>
<blockquote class="ipsBlockquote">1. Are you using Open Source BIRT, or commercial BIRT? What version?
<p> </p>
</blockquote>
<p> </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;font-size:14px;background-color:rgb(255,255,255);">I'm using an open source BIRT. The version is 3.7.1. </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;font-size:14px;background-color:rgb(255,255,255);"> </p>
<p> </p>
<blockquote class="ipsBlockquote">2. What timezone is set your database machine ?
<p> </p>
</blockquote>
<p> </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;font-size:14px;background-color:rgb(255,255,255);">The timezone is (UTC +01:00) Bruxelles, Copenhague, Madrid, Paris.</p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;font-size:14px;background-color:rgb(255,255,255);"> </p>
<br><p> </p>
<blockquote class="ipsBlockquote">3. Can you provide one sample value it is returning? <span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;font-size:14px;background-color:rgb(255,255,255);">5. Can you provide sample values of what you are expecting?</span></blockquote>
<p> </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;font-size:14px;background-color:rgb(255,255,255);"><span> if I should have a result 03:00, </span></p>
<ul><li>UTC - 10:00 Hawaii, I received 03:30, so 30 min diff</li>
<li>UTC - 09:00 Alaska,<span>I received 03:59, so 59 min diff</span></li>
<li>UTC - 08:00 Baja California,<span>I received 02:48, so -12 min diff</span></li>
<li>UTC - 09:00 Alaska,<span>I received 03:59, so 59 min diff</span></li>
<li><span>...</span></li>
</ul><blockquote class="ipsBlockquote">4. What timezone is set on your Application Server (if running OS BIRT), or iHub (if running commercial BIRT) machine?
<p> </p>
</blockquote>
<p> </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">The timezone on my application server is <span> (UTC +01:00) Bruxelles, Copenhague, Madrid, Paris.</span></p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">However, If I change the timezone on my database machine, the diff still existe and if I change the timezone on my application server, it's working (for some timezone)! Like : </p>
<ol><li><span>(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna, is working well.</span></li>
<li><span>(UTC +01:00) Bruxelles, Copenhague, Madrid, Paris. is not working</span></li>
</ol><p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Thanks a lot for your help! </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">For (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna, it's working well.</span></p>
Clement Wong
<p>Still trying to understand your setup to figure where the discrepancy is....</p>
<p> </p>
<p>1. What database server and version are you running?</p>
<p>2. What database client and version with BIRT are you using? Is there a specific JDBC URL used?</p>
<p>3. So let's say the time is stored in your database as 03:00 UTC +01:00, or you can use one real value returned:</p>
<p> </p>
<p> A. Outside of BIRT, if you use a database client, what does it show?</p>
<p> B. In the BIRT Designer, if you just <em>Preview Data</em> in the Edit Data Set, what does it show?</p>
<p> </p>
<p>4. I'm confused about your last observation where if you have a Berlin timezone which is UTC+01:00 and Paris timezone which is also UTC+01:00, there is different result?</p>
<p> </p>
<p> </p>
<p>5. Now that we have retrieved the time from the database, you want to calculate the current date/time on the application server, and subtract it from the date/time from the database to get the minutes?</p>
<p> </p>
<p>6. Where does the other time zones come into play? Is that something that you'll have the user select before running a report?</p>
<p> </p>
<p> </p>
<p>Have you thought of using retrieving the Unix / Epoch / POSIX time from the database? It might be easier to calculate since you'll be within a fixed reference of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970.</p>
<p> </p>
<p>For example, MySQL:</p>
<pre>
SELECT UNIX_TIMESTAMP(thedate) FROM thetable</pre>
<p>Then, in BIRT, you can calculate:</p>
<p> </p>
<p>/<span style="font-family:'courier new', courier, monospace;">/ GMT: Tue, 23 Aug 2016 22:28:12 GMT<br>
// Your time zone: Tuesday, August 23, 2016 3:28:12 PM GMT-7:00 DST<br>
var dbTime = 1471991292; <br>
var epochTime = BirtDateTime.now().getTime()/1000;<br><br>
(epochTime - dbTime) / 60;</span></p>
<p> </p>
<p> </p>
<p><span style="font-family:arial, helvetica, sans-serif;">Attached is a .rptdesign that I would like you to run in your Designer and Application Server and note what time zones you set for Java before running the report. Include the output if you would like to troubleshoot further.</span></p>