systime

Change-Id: Ibb0edbb28a8c5d7281b0f247124af1b984c3ac8e
diff --git a/mbtk/liblynq_lib/src/lynq_time.c b/mbtk/liblynq_lib/src/lynq_time.c
index a288c86..269527d 100644
--- a/mbtk/liblynq_lib/src/lynq_time.c
+++ b/mbtk/liblynq_lib/src/lynq_time.c
@@ -19,6 +19,7 @@
 #include "mbtk_net_control.h"
 #include "lynq_systime.h"
 #include "mbtk_type.h"
+#include "mbtk_log.h"
 
 
 #define MBTK_AT_NTP_LEN_MAX 128
@@ -57,7 +58,7 @@
 //int req_time_set(int type, char *time, int *cme_err);
 static int metis_strptime(char *str_time)
 {
-    printf("%s(), str_time:%s\n", __FUNCTION__, str_time);
+    LOGD("%s(), str_time:%s\n", __FUNCTION__, str_time);
     struct tm stm;
     char dateTime[30];
     struct timeval tv;
@@ -69,24 +70,24 @@
         tv.tv_usec = 0;	
         if(_t == -1)
         {
-            printf("Set time :%s", str_time);
-            printf("timestamp:%ld", _t);
-            printf("mktime error, reason: %s\n", strerror(errno));
+            LOGD("Set time :%s", str_time);
+            LOGD("timestamp:%ld", _t);
+            LOGD("mktime error, reason: %s\n", strerror(errno));
             return -1;
         }
 
         if(settimeofday(&tv, NULL)) {
-            printf("Set time :%s", str_time);
-            printf("timestamp:%ld", _t);
-            printf("mktime error, reason: %s\n", strerror(errno));
+            LOGD("Set time :%s", str_time);
+            LOGD("timestamp:%ld", _t);
+            LOGD("mktime error, reason: %s\n", strerror(errno));
             return -1;
         } 
 
-        printf("Success Set time to %s.\n", str_time);
+        LOGD("Success Set time to %s.\n", str_time);
         return 0;
 
     } else {
-        printf("Set time fail.");
+        LOGD("Set time fail.");
         return -1;
     }
     return 0;
@@ -97,14 +98,14 @@
 {
     if (mbtk_net_state_get() == MBTK_NET_STATE_OFF) 
     {
-        printf("Network is disconnected. Set time fail.");
+        LOGD("Network is disconnected. Set time fail.");
         if(NULL != ntp_flag)
        {
             *ntp_flag = -1;
        }
         return NULL;
     }
-    printf("Network is connected.");
+    LOGD("Network is connected.");
 
     char time_type[10];
     while(1){
@@ -116,7 +117,7 @@
             time_t time = 0;
             if((time = (time_t)mbtk_at_systime()) == 0) 
             {
-                printf("NTP client fail!\n");
+                LOGD("NTP client fail!\n");
                 if(NULL != ntp_flag)
                 {
                      *ntp_flag = -1;
@@ -131,7 +132,7 @@
             strftime(dateTime, 30, "%Y-%m-%d %H:%M:%S %A", &CurlocalTime);
 
       //      printf("dateTime:%s, %ld\n", dateTime, time+28800);  //cst
-            printf("dateTime:%s, %ld\n", dateTime, time);
+            LOGD("dateTime:%s, %ld\n", dateTime, time);
 
             struct timeval tv;
             tv.tv_sec = time;
@@ -139,16 +140,16 @@
             tv.tv_usec = 0;
 
             if(settimeofday(&tv, NULL)) {
-                printf("Set time :%s", dateTime);
-                printf("timestamp:%ld, tv.tv_sec:%ld\n", time, tv.tv_sec);
+                LOGD("Set time :%s", dateTime);
+                LOGD("timestamp:%ld, tv.tv_sec:%ld\n", time, tv.tv_sec);
 
                 if(settimeofday(&tv, NULL)) {
                     *ntp_flag = -1;
-                    printf("mktime error, reason: %s\n", strerror(errno));
+                    LOGD("mktime error, reason: %s\n", strerror(errno));
                     return NULL;
                 }
             } 
-            printf("Set time success\n");
+            LOGD("Set time success\n");
             lynq_set_rtc_time();
 #else
             
@@ -366,3 +367,4 @@
 }
 
 
+
diff --git a/mbtk/mbtk_gnssd/gnss_utils.c b/mbtk/mbtk_gnssd/gnss_utils.c
index b62aa85..d114b4b 100755
--- a/mbtk/mbtk_gnssd/gnss_utils.c
+++ b/mbtk/mbtk_gnssd/gnss_utils.c
@@ -532,18 +532,33 @@
 #endif
                 if( (mbtk_time_type_gnss_read() == LYNQ_TIME_TYPE_GNSS) && !mbtk_gnss_time_set_flag)
                 {
+#if 0
                     struct timeval tv;
                     tzset();   // auto set tz
-                    _t = _t - timezone;
-
+                //    _t = _t - timezone;
                     LOGD("timestamp:%ld,  %ld", _t,  timezone);
-
                     tv.tv_sec = _t;
+
+#else
+                    LOGD("_t: %ld\n", _t);
+                  struct tm CurlocalTime;
+                  localtime_r(&_t, &CurlocalTime);
+                  CurlocalTime.tm_hour += 8;    //cst+8 set for UTC
+                  char dateTime[30];
+                  strftime(dateTime, 30, "%Y-%m-%d %H:%M:%S %A", &CurlocalTime);
+                  LOGD("dateTime:%s, %ld\n", dateTime, _t);
+
+                  struct timeval tv;
+                  tv.tv_sec = _t;
+                  tv.tv_sec += 28800;  //cst 
+                  tv.tv_usec = 0;
+
+#endif
                     if(settimeofday(&tv, NULL)) {
-                        LOGD("%s: , Set time fail\n", __func__);
+                        LOGD("%s: 1111, Set time fail\n", __func__);
                         mbtk_gnss_time_set_flag = 0;
                     } else {
-                        LOGD("%s: , Set time success \n", __func__);
+                        LOGD("%s: 1111, Set time success \n", __func__);
                         system("hwclock -w rtc0");
                         mbtk_gnss_time_set_flag = 1;
                     }
@@ -554,4 +569,4 @@
 
     return 0;
 }
-#endif
\ No newline at end of file
+#endif