return CALENDAR_ERROR_NONE;
}
+static time_t _make_time(struct tm *time)
+{
+ time_t utc = mktime(time);
+
+ /* If an error occurs when isdst is 1, retry it after chaning isdst is 0 */
+ if (utc < 0 && time->tm_isdst != 0 ) {
+ time->tm_isdst = 0;
+ utc = mktime(time);
+ }
+ return utc;
+}
+
static long long int _get_event_alert_utime(const char *field, int event_id, time_t current)
{
int ret = 0;
int ret = 0;
char query[CAL_DB_SQL_MAX_LEN] = {0};
struct tm st = {0};
- tzset();
- localtime_r(¤t, &st);
- time_t mod_current = timegm(&st);
+ struct tm now_s = {0};
+ char buf[256] = {0};
+
+ localtime_r(¤t, &now_s);
+ snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d", (int)(now_s.tm_year + 1900),
+ (int)(now_s.tm_mon + 1), (int)now_s.tm_mday, (int)now_s.tm_hour,
+ (int)now_s.tm_min, (int)now_s.tm_sec);
+ DBG("Current time : (%s)", buf);
+
snprintf(query, sizeof(query), "SELECT %s FROM %s "
- "WHERE event_id=%d AND strftime('%%s', %s)>%ld ORDER BY %s LIMIT 1",
- field, CAL_TABLE_LOCALTIME_INSTANCE, event_id, field, mod_current, field);
+ "WHERE event_id=%d AND (strftime('%%s', %s) - strftime('%%s', '%s') > 0) ORDER BY %s LIMIT 1",
+ field, CAL_TABLE_LOCALTIME_INSTANCE, event_id, field, buf, field);
sqlite3_stmt *stmt = NULL;
ret = cal_db_util_query_prepare(query, &stmt);
if (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt))
datetime = (const char *)sqlite3_column_text(stmt, 0);
+
if (NULL == datetime || '\0' == *datetime) {
/* LCOV_EXCL_START */
ERR("Invalid datetime [%s]", datetime);
st.tm_hour = h;
st.tm_min = n;
st.tm_sec = s;
+ st.tm_isdst = cal_time_is_dst_savings();
- return (long long int)mktime(&st);
+ return (long long int)_make_time(&st);
}
static int64_t _get_todo_alert_utime(const char *field, int id, time_t now_t)
case CAL_SQLITE_ROW:
utime = (int64_t)sqlite3_column_int64(stmt, 0);
break;
- /* LCOV_EXCL_START */
+ /* LCOV_EXCL_START
case SQLITE_DONE:
ERR("No data");
- break;
+ break;*/ //Svace:371986
default:
ERR("Invalid return(%d)", ret);
break;
int ret = 0;
char query[CAL_DB_SQL_MAX_LEN] = {0};
struct tm st = {0};
- tzset();
- localtime_r(¤t, &st);
- time_t mod_current = timegm(&st);
+ struct tm now_s = {0};
+ char buf[256] = {0};
+
+ localtime_r(¤t, &now_s);
+ snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d", (int)(now_s.tm_year + 1900),
+ (int)(now_s.tm_mon + 1), (int)now_s.tm_mday, (int)now_s.tm_hour,
+ (int)now_s.tm_min, (int)now_s.tm_sec);
+ DBG("Current time : (%s)", buf);
+
snprintf(query, sizeof(query), "SELECT %s FROM %s "
- "WHERE id=%d AND strftime('%%s', %s)>%ld ORDER BY %s LIMIT 1",
- field, CAL_TABLE_SCHEDULE, event_id, field, mod_current, field);
+ "WHERE id=%d AND (strftime('%%s', %s) - strftime('%%s', '%s') > 0) ORDER BY %s LIMIT 1",
+ field, CAL_TABLE_SCHEDULE, event_id, field, buf, field);
sqlite3_stmt *stmt = NULL;
ret = cal_db_util_query_prepare(query, &stmt);
st.tm_hour = h;
st.tm_min = n;
st.tm_sec = s;
+ st.tm_isdst = cal_time_is_dst_savings();
- return (long long int)mktime(&st);
+ return (long long int)_make_time(&st);
}
/*
* time(NULL) is not appropriate as parameter.
st.tm_hour = h;
st.tm_min = n;
st.tm_sec = s;
- *tt_alert = mktime(&st);
+ st.tm_isdst = cal_time_is_dst_savings();
+ *tt_alert = _make_time(&st);
DBG("datetime[%s] to %02d:%02d:%02d (%ld)", datetime, h, n, s, *tt_alert);
}
}
sqlite3_finalize(stmt);
time_t current = time(NULL);
+
current += (tick * unit);
current -= 2; /* in case time passed */
}
break;
}
+ *tt_alert = utime - (tick * unit);
+
DBG("alert_time(%ld) = utime(%lld) - (tick(%d) * unit(%d))", *tt_alert, utime, tick, unit);
- *tt_alert = utime - (tick * unit);
return CALENDAR_ERROR_NONE;
}
st.tm_hour = h;
st.tm_min = n;
st.tm_sec = s;
- ad->alert_utime = (long long int)mktime(&st);
+ st.tm_isdst = cal_time_is_dst_savings();
+ ad->alert_utime = (long long int)_make_time(&st);
if (false == get_all) break;
}
sqlite3_finalize(stmt);
st.tm_hour = h;
st.tm_min = n;
st.tm_sec = s;
- ad->alert_utime = (long long int)mktime(&st) - (ad->tick * ad->unit);
+ st.tm_isdst = cal_time_is_dst_savings();
+ ad->alert_utime = (long long int)_make_time(&st) - (ad->tick * ad->unit);
if (false == get_all) break;
}
sqlite3_finalize(stmt);
st.tm_hour = h;
st.tm_min = n;
st.tm_sec = s;
- ad->alert_utime = (long long int)mktime(&st) - (ad->tick * ad->unit);
+ st.tm_isdst = cal_time_is_dst_savings();
+ ad->alert_utime = (long long int)_make_time(&st) - (ad->tick * ad->unit);
if (false == get_all) break;
}
sqlite3_finalize(stmt);
static void _cal_server_alarm_get_latest(time_t utime, bool get_all, GList **out_l)
{
+ int ret = 0;
CAL_FN_CALL();
RET_IF(NULL == out_l);
localtime_r(&utime, &st_local);
char datetime[CAL_STR_SHORT_LEN32] = {0};
- snprintf(datetime, sizeof(datetime), CAL_FORMAT_LOCAL_DATETIME,
+ ret = snprintf(datetime, sizeof(datetime), CAL_FORMAT_LOCAL_DATETIME,
st_local.tm_year +1900, st_local.tm_mon + 1, st_local.tm_mday,
st_local.tm_hour, st_local.tm_min, st_local.tm_sec);
+
+ if(ret < 0){
+ WARN("datetime is truncated (%s)",datetime);
+ }
+
DBG("get alert to register with given time (%ld) datetime[%s]", utime, datetime);
GList *l = NULL;
static GFunc _cal_server_alarm_print_cb(gpointer data, gpointer user_data)
{
struct _alarm_data_s *ad = (struct _alarm_data_s *)data;
- DBG("id(%d) unit(%d) tick(%d) type(%d) time(%lld) datetime[%s]",
- ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime);
+ DBG("id(%d) unit(%d) tick(%d) type(%d) time(%lld) datetime[%s] alert_utime[%lld]",
+ ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime, ad->alert_utime);
return 0;
}