One Star

Daylight saving time

Hi everybody,
as you may know, we change time this sunday (+1 hour). This causes me trouble cause I am working with dates (and especially diffDate). The problem is the following:
dateend=TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", "2012-03-26 00:00:00");
datestart=TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", "2012-03-25 00:00:00");
row1.test=TalendDate.diffDate(datestart, dateend,"ss");
//will return -82800 (86400 seconds - 3600)

whereas:
dateend=TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", "2012-03-27 00:00:00");
datestart=TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", "2012-03-26 00:00:00");
row1.test=TalendDate.diffDate(datestart, dateend,"ss");
//will return 86400 seconds

So I try to develop a routine to have a corrected date. The idea is to add one hour if the day is a sunlight saving one:
package routines;
import java.util.Date;
import routines.TalendDate;
public class CustomOperations {
public static Date correctTimeOffset(Date stupidDate)
{
Date stupidDateMinusOne;
Date correctedDate;

correctedDate=stupidDate;
stupidDateMinusOne=TalendDate.addDate(stupidDate, -1, "dd");

if ( Math.abs(TalendDate.diffDate(stupidDate, stupidDateMinusOne))<86400 )
{
correctedDate=TalendDate.addDate(stupidDate, 1, "hh");
}
return correctedDate;
}

but it does not work (problems with types). Any idea ?
Still, I do not know whether it is the right way to proceed: I fear that if I add 1 hour to the day, it will return the following day... no ?
11 REPLIES
One Star

Re: Daylight saving time

Hi
Sorry. I may misunderstood this.
I type in tJava as follow.
Date dateend=TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", "2012-03-26 00:00:00");
Date datestart=TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", "2012-03-25 00:00:00");
long test=TalendDate.diffDate(datestart, dateend,"ss");
System.out.println(test);

The return value is -86400...
Regards,
Pedro
One Star

Re: Daylight saving time

Hi Pedro,
I copied/paste your code in a tJava component in my installation. Result is really -82800... Bug ?
do you think this comes from a locale environment setting ? I am using version 5.0.2, Build id: r78327-20120216-0244
thanks !
laloune
One Star

Re: Daylight saving time

Hi
I have tested this both in TOS 5.0.1 and TOS 5.0.2.
The result is as follow.
I didn't encounter this issue before...
Regards,
Pedro
One Star

Re: Daylight saving time

wtf ?
where are you located ? which locale is your system set on ?
One Star

Re: Daylight saving time

Hi
I change the locale into GMT+3:30...
The result is still -86400...
Does anyone encounter this issue before?
Regards,
Pedro
One Star

Re: Daylight saving time

well, interesting indeed !
with locale GMT+3:30 => result is 86400
with my normal locale => result is -82800
but why ? and how could I workaround this problem though ?
One Star

Re: Daylight saving time

Hi all,
I still have this problem.
the solution could be to change the locale temporarily (for the time of job exec), to a locale that does not have any daylight saving time !
does somebody know whether this is possible ? for instance in a tJavaRow
Thanks in advance,
laloune
One Star

Re: Daylight saving time

Is this a JAVA issue?
One Star

Re: Daylight saving time

well I do not know very well. It is a problem with locale (days 25th march 20112 is only 82800 minutes long (instead of 86400)
then when using the TalendDate.diffDate formula, it does not return correct result...
One Star

Re: Daylight saving time

Hi everybody,
finally found a workaround solution: I execute my job with the following JVM parameter: -Duser.timezone=UTC
no more dst problems then !
thanks for your support though
One Star

Re: Daylight saving time

Hi
Great! Thanks for your feedback.
Regards,
Pedro