[Groonga-commit] groonga/groonga at d4e478f [master] time_format_iso8601 windows: stop to use _get_timezone()

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jul 4 11:42:41 JST 2018


Kouhei Sutou	2018-07-04 11:42:41 +0900 (Wed, 04 Jul 2018)

  New Revision: d4e478f58a7e60d894ebf8c9cb581a763f64fed5
  https://github.com/groonga/groonga/commit/d4e478f58a7e60d894ebf8c9cb581a763f64fed5

  Message:
    time_format_iso8601 windows: stop to use _get_timezone()
    
    It crashes.

  Modified files:
    plugins/functions/time.c

  Modified: plugins/functions/time.c (+16 -10)
===================================================================
--- plugins/functions/time.c    2018-07-03 17:22:24 +0900 (9d36c4ded)
+++ plugins/functions/time.c    2018-07-04 11:42:41 +0900 (dab8435db)
@@ -30,6 +30,10 @@
 #include <stdlib.h>
 #include <time.h>
 
+#ifdef WIN32
+# define timegm _mkgmtime
+#endif /* WIN32 */
+
 typedef enum {
   GRN_TIME_CLASSIFY_UNIT_SECOND,
   GRN_TIME_CLASSIFY_UNIT_MINUTE,
@@ -505,6 +509,8 @@ func_time_format_iso8601(grn_ctx *ctx, int n_args, grn_obj **args,
   {
     int64_t time_raw;
     struct tm tm;
+    int64_t time_sec;
+    int32_t time_usec;
     grn_obj *formatted_time;
 
     time_raw = GRN_TIME_VALUE(time);
@@ -512,6 +518,8 @@ func_time_format_iso8601(grn_ctx *ctx, int n_args, grn_obj **args,
       return NULL;
     }
 
+    GRN_TIME_UNPACK(time_raw, time_sec, time_usec);
+
     formatted_time = grn_plugin_proc_alloc(ctx, user_data, GRN_DB_TEXT, 0);
     if (!formatted_time) {
       return NULL;
@@ -526,23 +534,21 @@ func_time_format_iso8601(grn_ctx *ctx, int n_args, grn_obj **args,
                     tm.tm_hour,
                     tm.tm_min,
                     tm.tm_sec,
-                    (int32_t)(time_raw % GRN_TIME_USEC_PER_SEC));
+                    time_usec);
 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
     grn_text_printf(ctx,
                     formatted_time,
                     "%+03d:%02d",
                     (int32_t)(tm.tm_gmtoff / 3600),
                     abs(tm.tm_gmtoff % 3600));
-#elif defined(WIN32) /* HAVE_STRUCT_TM_TM_GMTOFF */
+#else
     {
-      long gmtoff;
-      if (_get_timezone(gmtoff) == 0) {
-        grn_text_printf(ctx,
-                        formatted_time,
-                        "%+03d:%02d",
-                        (int32_t)(gmtoff / 3600),
-                        abs(gmtoff % 3600));
-      }
+      time_t gmtoff = timegm(&tm) - time_sec;
+      grn_text_printf(ctx,
+                      formatted_time,
+                      "%+03d:%02d",
+                      (int32_t)(gmtoff / 3600),
+                      abs(gmtoff % 3600));
     }
 #endif /* HAVE_STRUCT_TM_TM_GMTOFF */
     return formatted_time;
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180704/4ceafaab/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index