How to set first day of week for TalendDate class

Highlighted
Five Stars

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:
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)
Highlighted
One Star

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.
 ret = c.get(Calendar.DAY_OF_WEEK);

So you can't change it which is predefined in JDK.
Regards,
Pedro
Highlighted
Five Stars

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). Smiley Happy 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.
Highlighted
One Star

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.
 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/api/java/util/Calendar.html#setFirstDayOfWeek(int)
Regards,
Pedro

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog