+QList<QTime> AbstractSearchClient::TimesFromString(const QList<QString> &time_strings)
+{
+ QList<QTime> schedule_times;
+ bool am_pm = false;
+ Q_FOREACH(const QString time_str, time_strings) {
+ if (time_str.endsWith("am", Qt::CaseInsensitive) || time_str.endsWith("pm", Qt::CaseInsensitive)) {
+ am_pm = true;
+ }
+ }
+ if (am_pm) {
+ int i = 0;
+ bool am = true;
+ while (i < time_strings.length()) {
+ int j = i;
+ while (i < time_strings.length()) {
+ if (time_strings[i].endsWith("am", Qt::CaseInsensitive)) {
+ am = true;
+ break;
+ } else if (time_strings[i].endsWith("pm", Qt::CaseInsensitive)) {
+ am = false;
+ break;
+ }
+ ++i;
+ }
+ while (j < i) {
+ QString time_str = time_strings[j] + (am ? "am" : "pm");
+ QTime time = TimeUtils::FromTimeString(time_str);
+ if (time.isValid()) {
+ schedule_times.append(time);
+ } else {
+ std::cout << "ERROR: time " << qPrintable(time_str) << " is invalid." << std::endl;
+ }
+ ++j;
+ }
+ if (i < time_strings.length()) {
+ QString time_str = time_strings[i];
+ QTime time = TimeUtils::FromTimeString(time_str);
+ if (time.isValid()) {
+ schedule_times.append(time);
+ } else {
+ std::cout << "ERROR: time " << qPrintable(time_str) << " is invalid." << std::endl;
+ }
+ schedule_times.append(time);
+ }
+ ++i;
+ }
+ } else {
+ Q_FOREACH(const QString time_str, time_strings) {
+ QTime time = TimeUtils::FromTimeString(time_str);
+ if (time.isValid()) {
+ schedule_times.append(time);
+ } else {
+ std::cout << "ERROR: time " << qPrintable(time_str) << " is invalid." << std::endl;
+ }
+ }
+ }
+ return schedule_times;
+}
+