void EventWrapper::setProgressToPlatformEvent()
{
- if (!m_platformEvent) {
- ThrowMsg(UnknownException, "Null platform pointer.");
- }
+ if (!m_platformEvent) {
+ ThrowMsg(UnknownException, "Null platform pointer.");
+ }
- int progress = m_abstractEvent->getProgress();
- if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
- CAL_VALUE_INT_PROGRESS,
- progress)) {
- ThrowMsg(PlatformException, "Can't set visibility.");
- }
+ int progress = m_abstractEvent->getProgress();
+ if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
+ CAL_VALUE_INT_PROGRESS,
+ progress)) {
+ ThrowMsg(PlatformException, "Can't set visibility.");
+ }
}
CalendarEventPtr EventWrapper::convertPlatformEventToAbstractEvent()
std::vector<std::string> daysOfTheWeek;
char* byday = calendar_svc_struct_get_str(m_platformEvent, CALS_VALUE_TXT_RRULE_BYDAY);
LogInfo("Loaded byday: "<<byday);
- char* pch = strtok(byday, ",");
- while (NULL != pch) {
- daysOfTheWeek.push_back(pch);
- pch = strtok(NULL, ",");
+ if (byday) {
+ char *saveptr = NULL;
+ char* pch = strtok_r(byday, ",", &saveptr);
+ while (NULL != pch) {
+ daysOfTheWeek.push_back(pch);
+ pch = strtok_r(NULL, ",", &saveptr);
+ }
}
rrule->setDaysOfTheWeek(daysOfTheWeek);
LogInfo("Number of daysOfTheWeek: "<<rrule->getDaysOfTheWeek().size());
// load the recurrence end date
long long int endDate = calendar_svc_struct_get_lli(m_platformEvent, CALS_VALUE_LLI_RRULE_UNTIL_UTIME);
rrule->setEndDate(endDate);
- LogDebug("endDate from platform = " << endDate);
+ LogDebug("endDate from platform = " << endDate);
// load the exceptions
std::vector<long long int> exceptions;
char* exdate = calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_EXDATE);
LogInfo("Loaded exdate: "<<exdate);
- pch = strtok(exdate, ",");
- while (NULL != pch) {
- std::stringstream ss(pch);
- long long int oneException;
- ss>>oneException;
- exceptions.push_back(oneException);
- pch = strtok(NULL, ",");
+ if (exdate) {
+ char *saveptr = NULL;
+ char *pch = strtok_r(exdate, ",", &saveptr);
+ while (NULL != pch) {
+ std::stringstream ss(pch);
+ long long int oneException;
+ ss>>oneException;
+ exceptions.push_back(oneException);
+ pch = strtok_r(NULL, ",", &saveptr);
+ }
}
rrule->setExceptions(exceptions);
LogInfo("Number of exceptions: "<<rrule->getExceptions().size());
m_platformEvent,
CAL_VALUE_TXT_CATEGORIES);
- if( categories ) {
- LogInfo("Loaded categories: "<<categories);
+ if( categories ) {
+ LogInfo("Loaded categories: "<<categories);
- char* pch = strtok(categories, ",");
- while (NULL != pch) {
- m_abstractEvent->getCategories()->push_back(pch);
- pch = strtok(NULL, ",");
- }
- }
+ char *saveptr = NULL;
+ char* pch = strtok_r(categories, ",", &saveptr);
+ while (NULL != pch) {
+ m_abstractEvent->getCategories()->push_back(pch);
+ pch = strtok_r(NULL, ",", &saveptr);
+ }
+ }
LogInfo("Number of categories: "<<m_abstractEvent->getCategories()->size());
}
ThrowMsg(UnknownException, "Null platform pointer.");
}
- int parentId = calendar_svc_struct_get_int(m_platformEvent,
- CAL_VALUE_INT_ORIGINAL_EVENT_ID);
+ int parentId = calendar_svc_struct_get_int(m_platformEvent,
+ CAL_VALUE_INT_ORIGINAL_EVENT_ID);
m_abstractEvent->setParentId(parentId);
}
TimeUtilTools util;
Calendar *cal = myCalendar->clone();
- if (duration.unit == DAYS_UNIT) {
- cal->add(UCAL_DATE, util.toint32_t(duration.length), ec);
- } else if (duration.unit == MINUTES_UNIT) {
- cal->add(UCAL_MINUTE, util.toint32_t(duration.length), ec);
- } else if (duration.unit == HOURS_UNIT) {
- cal->add(UCAL_HOUR_OF_DAY, util.toint32_t(duration.length), ec);
- } else if (duration.unit == MSECS_UNIT) {
- cal->add(UCAL_MILLISECOND, util.toint32_t(duration.length), ec);
- } else {
- cal->add(UCAL_SECOND, util.toint32_t(duration.length), ec);
+ long long length = duration.length;
+ short unit = duration.unit;
+ int msec=0, sec=0, min=0, hour=0;
+ long long day=0;
+
+ if (unit == MSECS_UNIT) {
+ msec = length % 1000;
+ length /= 1000;
+ unit = SECONDS_UNIT;
+ }
+ if ((length != 0) && (unit == SECONDS_UNIT)) {
+ sec = length % 60;
+ length /= 60;
+ unit = MINUTES_UNIT;
+ }
+ if ((length != 0) && (unit == MINUTES_UNIT)) {
+ min = length % 60;
+ length /= 60;
+ unit = HOURS_UNIT;
+ }
+ if ((length != 0) && (unit == HOURS_UNIT)) {
+ hour = length % 24;
+ length /= 24;
+ unit = DAYS_UNIT;
+ }
+ day = length;
+ LogDebug("day:"<<day<<" hour:"<<hour<<" min:"<<min<<" sec:"<<sec<<" msec:"<<msec);
+ try {
+ if (msec != 0) {
+ cal->add(UCAL_MILLISECOND, util.toint32_t(msec), ec);
+ if (!U_SUCCESS(ec))
+ Throw(Commons::PlatformException);
+ }
+ if (sec != 0) {
+ cal->add(UCAL_SECOND, util.toint32_t(sec), ec);
+ if (!U_SUCCESS(ec))
+ Throw(Commons::PlatformException);
+ }
+ if (min != 0) {
+ cal->add(UCAL_MINUTE, util.toint32_t(min), ec);
+ if (!U_SUCCESS(ec))
+ Throw(Commons::PlatformException);
+ }
+ if (hour != 0) {
+ cal->add(UCAL_HOUR_OF_DAY, util.toint32_t(hour), ec);
+ if (!U_SUCCESS(ec))
+ Throw(Commons::PlatformException);
+ }
+ while (day != 0) {
+ LogDebug("1st day : " << day);
+ int amount = 0;
+
+ if (day < INT_MIN)
+ amount = INT_MIN;
+ else if (day > INT_MAX)
+ amount = INT_MAX;
+ else
+ amount = day;
+
+ day -= amount;
+ LogDebug("amount : " << amount);
+ LogDebug("2nd day : " << day);
+ cal->add(UCAL_DATE, util.toint32_t(amount), ec);
+ if (!U_SUCCESS(ec))
+ Throw(Commons::PlatformException);
+ } ;
+ } catch (Commons::PlatformException) {
+ delete cal;
+ ThrowMsg(Commons::PlatformException, "Calendar error in addDuration");
}
+
TZDateProperties result = _makeProperties(cal);
util.printDate(cal);
delete cal;