• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » How to set first day of week for TalendDate class

#1 2012-04-11 01:43:25

atomic
New member
Registered: 2012-04-11
Posts: 2

How to set first day of week for TalendDate class

Hello, I'm wondering how to configure locale settings to define Monday as the first day of the week. For example, today is Wednesday, and when I execute:

Code:

TalendDate.getPartOfDate("DAY_OF_WEEK", TalendDate.getCurrentDate() );

it returns 4, indicating that the first day of the week is Sunday. I would like it to return 3.

I'm using TOS 5.0.1 with Java, on Win server 2008.

(This also affects week of year in a similar way)

Offline

#2 2012-04-11 07:02:13

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: How to set first day of week for TalendDate class

Hi

Welcome to Talend Community!

The method getPartDate() gets the return value from java.util.Calendar.

Code:

 ret = c.get(Calendar.DAY_OF_WEEK);

So you can't change it which is predefined in JDK.

Regards,
Pedro


Only Paranoid Survive.

Offline

#3 2012-05-03 02:12:28

atomic
New member
Registered: 2012-04-11
Posts: 2

Re: How to set first day of week for TalendDate class

Thanks Pedro. I guess I can workaround the day of week issue with some custom code.
(if day-name = Monday, return 1, if Tues return 2 etc...)

However, the issue with week of year is more challenging. Is there a way to alter the calendar settings in a tMap component? I am a bit of a Java simpleton, but it looks like you may be able to construct a calendar with various locale settings.

For example, if 1-Jan is a Sunday and the first day of the week is Monday, then the week-of-year of 1-Jan should be 52, and week-of-year of 2-Jan should be 1.

Perhaps even more challenging, is I would like to be able to set the first day of the year to be 1-Jul to construct a financial calendar (the Australian FY starts on 1-Jul). smile In this case, week-of-year #1 begins on the first Monday after 1-Jul, and 2-Aug would be the 33rd day of the year and so on.

Offline

#4 2012-05-03 08:39:07

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: How to set first day of week for TalendDate class

Hi

After reading java.util.Calendar API, there is a method called setFirstDayOfWeek().
But an interesting thing is that the method can only effect the return values of WEEK_OF_MONTH and WEEK_OF_YEAR. For DAY_OF_WEEK, it does nothing.
Here is my test code.

Code:

 Calendar c = Calendar.getInstance();
 c.setTime(TalendDate.getCurrentDate());
 c.setFirstDayOfWeek(Calendar.MONDAY);
 int rec = c.get(Calendar.WEEK_OF_MONTH);
 System.out.println(rec);

I think the best way is creating a new custom routine. Just add this line--  c.setFirstDayOfWeek(Calendar.MONDAY);

The API URL:http://docs.oracle.com/javase/6/docs/ap … fWeek(int)

Regards,
Pedro


Only Paranoid Survive.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » How to set first day of week for TalendDate class

Board footer

Powered by FluxBB