Fix use of "time offset" parameter, and add test to make sure I don't break it again :-)
authorJelmer Vernooij <jelmer@samba.org>
Tue, 23 Dec 2008 21:10:34 +0000 (22:10 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 23 Dec 2008 21:10:34 +0000 (22:10 +0100)
lib/util/tests/time.c
lib/util/time.c
lib/util/time.h
source3/lib/time.c
source3/param/loadparm.c

index 4a31566b4280a00c34f3287fce2b49de5984e0f1..e24c5fe5ef50723868a85df4a80743caded113a2 100644 (file)
@@ -58,6 +58,21 @@ static bool test_timestring(struct torture_context *tctx)
        return true;
 }
 
+static bool test_get_time_zone(struct torture_context *tctx)
+{
+       time_t t = time(NULL);
+       int old_extra_time_offset = extra_time_offset;
+       int old_offset, new_offset;
+       /* test that extra_time_offset works */
+
+       old_offset = get_time_zone(t);
+       extra_time_offset = 42;
+       new_offset = get_time_zone(t);
+       extra_time_offset = old_extra_time_offset;
+       torture_assert_int_equal(tctx, old_offset+60*42, new_offset,
+                                "time offset not used");
+       return true;
+}
 
 
 struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx)
@@ -65,6 +80,7 @@ struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx)
        struct torture_suite *suite = torture_suite_create(mem_ctx, "TIME");
 
        torture_suite_add_simple_test(suite, "null_time", test_null_time);
+       torture_suite_add_simple_test(suite, "get_time_zone", test_get_time_zone);
        torture_suite_add_simple_test(suite, "null_nttime", test_null_nttime);
        torture_suite_add_simple_test(suite, "http_timestring", 
                                                                  test_http_timestring);
index a001e5f66e0682c8caa93b2c95c65085b2222db7..eadafe4562bc5cd2a692cec5dd12dd4fa9ca6a90 100644 (file)
@@ -628,6 +628,9 @@ static int tm_diff(struct tm *a, struct tm *b)
        return seconds;
 }
 
+
+int extra_time_offset=0;
+
 /**
   return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
  */
@@ -641,7 +644,7 @@ _PUBLIC_ int get_time_zone(time_t t)
        tm = localtime(&t);
        if (!tm)
                return 0;
-       return tm_diff(&tm_utc,tm);
+       return tm_diff(&tm_utc,tm)+60*extra_time_offset;
 }
 
 struct timespec nt_time_to_unix_timespec(NTTIME *nt)
index 42644a3954d6a154335d455b7b885d2bd47c4837..e40de2de3df9431c9d93aed6415939b1ea06a59e 100644 (file)
@@ -239,4 +239,7 @@ struct timespec convert_time_t_to_timespec(time_t t);
 
 bool null_timespec(struct timespec ts);
 
+/** Extra minutes to add to the normal GMT to local time conversion. */
+extern int extra_time_offset;
+
 #endif /* _SAMBA_TIME_H_ */
index db2266fcbf1697d1802099471670db7ac907cb27..cae6b479b0d5c41f8b763c5ad99829179a249ebe 100644 (file)
@@ -131,8 +131,6 @@ time_t convert_uint32_to_time_t(uint32_t u)
        return (time_t)u;
 }
 
-int extra_time_offset=0;
-
 /****************************************************************************
  Check if NTTIME is 0.
 ****************************************************************************/
index 8f03ae8fd73601b71937a865aa12fcab3e35d78e..274c79904e5b8c640e0631f8ca77cbd5521f5d5f 100644 (file)
@@ -94,8 +94,6 @@ static int config_backend = CONFIG_BACKEND_FILE;
 #define USERSHARE_VALID 1
 #define USERSHARE_PENDING_DELETE 2
 
-extern int extra_time_offset;
-
 static bool defaults_saved = False;
 
 struct param_opt_struct {