Categories
Bada Tutorials

Developing bada: DateTime – workday or holiday?

In my current bada application project I encountered the task to find out what day of the week a specific date (DateTime object with Day, Month and Year parameters). Thanks to the hardworking developer huydung and other community members over at badadev.com I could write a fine working function you can simply add to your header file.

static bool IsWeekday(Osp::Base::DateTime *Date) {
 Osp::Locales::Calendar *calendar = Osp::Locales::Calendar::CreateInstanceN();
 calendar->SetTime(Date->GetYear(), Date->GetMonth(), Date->GetDay());

 int dayOfWeek = calendar->GetTimeField(Osp::Locales::TIME_FIELD_DAY_OF_WEEK);

 if(dayOfWeek == 1 || dayOfWeek == 7) return false; // check for Sunday and Saturday
 if(Date->GetMonth() == 1 && Date->GetDay() == 1) return false  // check for New Year's Day
 if(Date->GetMonth() == 5 && Date->GetDay() == 1) return false;  // check for Labour Day
 if(Date->GetMonth() == 12 && (Date->GetDay() == 25 || Date->GetDay() == 26)) return false;  // check for Christmas

 return true;
 }

To recieve a boolean true or false value whether your date to be checked is a holiday (Saturday and Sunday, additionally I added official holidays like New Year’s Day, Labour Day and Christmas of course) or a workday (Monday to Friday) you can invoke the function with bool isWorkday = IsWeekday(DateTime_Pointer);
Have fun with it.

Leave a Reply