From 2c637550b731a4f3f5a1324d05c77f2a491c5625 Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Mon, 2 Apr 2018 11:20:32 +0900 Subject: [PATCH] check alarm time Change-Id: I97f5d033dd50a6ce6fdcd28f332d799710c01d97 --- common/cal_time.cpp | 19 +++++++++++++++++++ common/cal_time.h | 1 + server/cal_server_alarm.c | 23 ++++++++++++----------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/common/cal_time.cpp b/common/cal_time.cpp index a13d4c5..af7307b 100644 --- a/common/cal_time.cpp +++ b/common/cal_time.cpp @@ -452,3 +452,22 @@ bool cal_time_is_available_tzid(char *tzid) return false; } +int _get_dst_savings(char *tzid) +{ + UChar utf16_timezone[CAL_STR_SHORT_LEN64] = {0}; + u_uastrncpy(utf16_timezone, tzid, sizeof(utf16_timezone)); + + UErrorCode status = U_ZERO_ERROR; + + return ucal_getDSTSavings(utf16_timezone, &status); +} + +bool cal_time_is_dst_savings(void) +{ + char buf[128] = {0}; + ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf) -1); + + char *timezone = buf + 20; /* /usr/share/zoneinfo/ */ + return _get_dst_savings(timezone) == 0 ? false : true; +} + diff --git a/common/cal_time.h b/common/cal_time.h index 2402a03..2c9450b 100644 --- a/common/cal_time.h +++ b/common/cal_time.h @@ -50,6 +50,7 @@ void cal_time_get_nth_wday(long long int t, int *nth, int *wday); void cal_time_get_datetime(long long int t, int *y, int *m, int *d, int *h, int *n, int *s); void cal_time_get_local_datetime(char *tzid, long long int t, int *y, int *m, int *d, int *h, int *n, int *s); bool cal_time_is_available_tzid(char *tzid); +bool cal_time_is_dst_savings(void); #ifdef __cplusplus } diff --git a/server/cal_server_alarm.c b/server/cal_server_alarm.c index 40bbced..705ae40 100644 --- a/server/cal_server_alarm.c +++ b/server/cal_server_alarm.c @@ -169,12 +169,9 @@ static int _get_event_alert_localtime(const char *field, int event_id, time_t cu 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); 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) - %ld > 0) ORDER BY %s LIMIT 1", + field, CAL_TABLE_LOCALTIME_INSTANCE, event_id, field, current, field); sqlite3_stmt *stmt = NULL; ret = cal_db_util_query_prepare(query, &stmt); @@ -209,6 +206,7 @@ static int _get_event_alert_localtime(const char *field, int event_id, time_t cu 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); } @@ -255,12 +253,9 @@ static int _get_todo_alert_localtime(const char *field, int event_id, time_t cur 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); 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) - %ld > 0) ORDER BY %s LIMIT 1", + field, CAL_TABLE_SCHEDULE, event_id, field, current, field); sqlite3_stmt *stmt = NULL; ret = cal_db_util_query_prepare(query, &stmt); @@ -295,6 +290,7 @@ static int _get_todo_alert_localtime(const char *field, int event_id, time_t cur 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); } @@ -362,6 +358,7 @@ static int cal_server_alarm_get_alert_time(int alarm_id, time_t *tt_alert) st.tm_hour = h; st.tm_min = n; st.tm_sec = s; + st.tm_isdst = cal_time_is_dst_savings(); *tt_alert = mktime(&st); DBG("datetime[%s] to %02d:%02d:%02d (%ld)", datetime, h, n, s, *tt_alert); } @@ -400,9 +397,10 @@ static int cal_server_alarm_get_alert_time(int alarm_id, time_t *tt_alert) } 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; } @@ -515,6 +513,7 @@ static void _cal_server_alarm_get_upcoming_specific_localtime(const char *dateti st.tm_hour = h; st.tm_min = n; st.tm_sec = s; + st.tm_isdst = cal_time_is_dst_savings(); ad->alert_utime = (long long int)mktime(&st); if (false == get_all) break; } @@ -633,6 +632,7 @@ static void _cal_server_alarm_get_upcoming_nonspecific_event_localtime(const cha st.tm_hour = h; st.tm_min = n; st.tm_sec = s; + st.tm_isdst = cal_time_is_dst_savings(); ad->alert_utime = (long long int)mktime(&st) - (ad->tick * ad->unit); if (false == get_all) break; } @@ -750,6 +750,7 @@ static void _cal_server_alarm_get_upcoming_nonspecific_todo_localtime(const char st.tm_hour = h; st.tm_min = n; st.tm_sec = s; + st.tm_isdst = cal_time_is_dst_savings(); ad->alert_utime = (long long int)mktime(&st) - (ad->tick * ad->unit); if (false == get_all) break; } -- 2.7.4