What’s the first day of the week?

Posted: 10 September 2009 in Custom instantiation, Java, Teamsite, Worfklow models, Workflows

I was doing something the other day that had to do with customising an instantiation form for a workflow. It was meant to pass a day of the week to a workflow and I wanted it to be easy. I was going to put a drop down list of strings ranging Monday to Sunday and pass that to the workflow.

Parsing the date inside the workflow task meant that an integer from 0 to 6 was going to be more appropriate but I didn’t know what 0 represented, so I wrote the little java snippet below to help me out:

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class CalendarLocaleTest {

 public static void main(String[] args){
 Locale locale = Locale.ENGLISH;
 Calendar cal = Calendar.getInstance(locale);
 SimpleDateFormat dateFormat = new SimpleDateFormat("EEEEE",locale);

 for (int dayOfWeek=0; dayOfWeek<7;dayOfWeek++){
 System.out.println(dayOfWeek + " - " + dateFormat.format(cal.getTime()) + (dayOfWeek==cal.getFirstDayOfWeek()?" *first day of the week":""));

This led me to write the instantiation drop-down list looking like this (I work in the UK):

<checkbox multiple=”t” required=”t”>
<option label=”Sunday” value=”1″/>
<option label=”Monday” value=”2″/>
<option label=”Tuesday” value=”3″/>
<option label=”Wednesday” value=”4″/>
<option label=”Thursday” value=”5″/>
<option label=”Friday” value=”6″/>
<option label=”Saturday” value=”0″/>

This could also (and probably should) be turned into a datasource displaying the days in the locale of the client browser. Right now, this was sufficient for me.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s