Week number issue when executing under a Linux Server

One Star

Week number issue when executing under a Linux Server

Hi,
I created a job in Talend under windows that works well if I execute it in my PC. When I export it under the Linux Server of my company, I have an issur with the week number.
The job is the get a csv file on a server and to put it on a mysql database.
The name of the csv file is weekly_counters_ + week number (actually, the last week number)
The tftpGet component have this mask file :
"weekly_counters_" +TalendDate.formatDate("yyyyww",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd")) + ".csv"
The job should be execute each monday on the past week data.
For example if we are in week 10 on the 2011-03-07, the file name on the server is "weekly_counters_201109.csv".
So, if it starts from my pc, it works well and on the linux server if have the following error message :
java.io.FileNotFoundExeption : c:/weekly_counters_201110.csv
I guess it is an issue on the Linux java environnement configuration but I wanted to know if I can do something on the Talend part to force java to use the right Calendar? If it is not possible what should I do the the java of the server?
Thank you very much for any help.
Regards,
Patrick V
Community Manager

Re: Week number issue when executing under a Linux Server

Hi
For example if we are in week 10 on the 2011-03-07, the file name on the server is "weekly_counters_201109.csv".

We are in week 11 on the 2011-03-07.
"java.io.FileNotFoundExeption : c:/weekly_counters_201110.csv

1. Please check the local time setting in Linux server.
2. Do you run the job in PC and Linux server at the same time?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Week number issue when executing under a Linux Server

Hi,
Thanks for your answer and time.
Actually, we are in week 10. Check here : http://www.calendar-365.com/week-number.html
1. The Linux server is good and if i make the command "date +%W" today, I have 10 as an answer and if if make date --date '1 day ago' +%%W (that means yesterday) if have 09 as a result. So I conclude that the problem is in the java part...???
2. I am running the job on th PC and on the Server the same time.
Thank you.
Regards,
Patrick VALLET
Community Manager

Re: Week number issue when executing under a Linux Server

Hi
Try to use Calendar instead of TalendDate.formatDate("yyyyww", date), add a tJava at the beginning of job and hard code the following code:
java.util.Calendar c=java.util.Calendar.getInstance();
c.setTime(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"));
int week =c.get(java.util.Calendar.WEEK_OF_YEAR);
globalMap.put("week", week);

Set the file name as:
"weekly_counters_" +(Integer)globalMap.get("week") + ".csv"
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Week number issue when executing under a Linux Server

Thank you for this idea.
I am trying it but as I am a beginner in java I have a little problem to put the week of the year in 2 digits as the file name is like "yyyyww.csv", so for week number less than 10, I need to add a zeron before. Can we do it with a Format function or do i have to use a "If...then...else" form?
Regards
One Star

Re: Week number issue when executing under a Linux Server

Hi,
Finally, I tried the "if then else" structure but the result is the same. Works fine on my PC and don't give me the right week number on the server.
java.util.Calendar c=java.util.Calendar.getInstance();
c.setTime(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"));
int week =c.get(java.util.Calendar.WEEK_OF_YEAR);
int year=c.get(java.util.Calendar.YEAR);
String num="";
if (week<10)
{num="0";}
globalMap.put("week", week);
globalMap.put("num", num);
globalMap.put("year", year);
I am still looking for a good solution.
Thank you.
Patrick V
Community Manager

Re: Week number issue when executing under a Linux Server

Hi
try
java.util.Calendar c=java.util.Calendar.getInstance();
c.setTime(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"));
int week =c.get(java.util.Calendar.WEEK_OF_YEAR);
int year=c.get(java.util.Calendar.YEAR);
String num="";
if (week<10){
globalMap.put("week", "0"+week);
}else{
globalMap.put("week", String.valueOf(week));
}
globalMap.put("num", num);
globalMap.put("year", year);

Set the file name as:
"weekly_counters_" +(String)globalMap.get("week") + ".csv"
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Week number issue when executing under a Linux Server

Hi shong,
I did approximetely the same thing and as I said the issue is still the same. Works well on my Pc and does not work on the server.
On the server the 6 March 2011(sunday) is the beginning of the Week 11 and on my PC, the same date is consider as the last day of the week 9.
If there is not workaround I should maybe ask to the management to update the JVM on the server and make sure that ISO 8601 is setted at the installation?
Thank you.
Regards,
Patrick V
One Star

Re: Week number issue when executing under a Linux Server

hi
Can you excecute a small java program in your Linux server to get week and check is it same as in talend.
One Star

Re: Week number issue when executing under a Linux Server

Thank for your time. I did the test and the week is not the same when I run a programm under the java of the server.
"Java server the 6 March 2011(sunday) is the beginning of the Week 11 / Java on my PC, the same date is consider as the last day of the week 9."
I don' know what I need to do to change local variable of the java serverSmiley Sad.
regards,
Patrick V
One Star

Re: Week number issue when executing under a Linux Server

Hi
change the code like
java.util.Calendar c=new java.util.GregorianCalendar().getInstance();

hope it will help you
One Star

Re: Week number issue when executing under a Linux Server

Thanks. Unfortunately the result is the same on the server instead I specify the calendar is a gregorian one.
Very weird.
I let you know if I found out what was wrong.
Regards
PV
One Star

Re: Week number issue when executing under a Linux Server

Yes, thanks. On the Linux server, il I put "date +W%", I have the good week number. It is in the java that the week number is wrongSmiley Sad.
Regards
Patrick V