2012-05-09

Kettle Javascript fail

I was working on a javascript step in a Pentaho Kettle script and could not for the life of me figure out why it wasn't working as expected. An excerpt follows. It takes a bunch of boolean values and ORs them down to a single boolean.

var is_holiday = (is_variable_date_holiday || is_fixed_date_holiday || is_nth_day_of_month_holiday)


And... it doesn't work as expected. Apparently the handling of boolean type data is somehow going insane. My final solution:

var is_holiday = false;

var holiday_name = '';
if (is_fixed_date_holiday == true)
{
is_holiday = true;
holiday_name = fixed_date_holiday_name;
};
if (is_variable_date_holiday == true)
{
is_holiday = true;
holiday_name = variable_holiday_name;
};
if (is_nth_day_of_month_holiday == true)
{
is_holiday = true;
holiday_name = nth_day_holiday_name;
};

var is_working_day = (is_weekend == true || is_holiday == true) ? false : true;

Yes. It really is that ugly.

0 comments: