diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-12-23 22:10:34 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-12-23 22:10:34 +0100 |
commit | ef80d1b794a209ee446c7a586530a5fdd51175f2 (patch) | |
tree | 9c368f4a0d281ca1ba48e575fc25638d59dc27ef | |
parent | d0eeb9aa8db42ed1fc18024614560820354e6dfa (diff) | |
download | samba-ef80d1b794a209ee446c7a586530a5fdd51175f2.tar.gz samba-ef80d1b794a209ee446c7a586530a5fdd51175f2.tar.bz2 samba-ef80d1b794a209ee446c7a586530a5fdd51175f2.zip |
Fix use of "time offset" parameter, and add test to make sure I don't break it again :-)
-rw-r--r-- | lib/util/tests/time.c | 16 | ||||
-rw-r--r-- | lib/util/time.c | 5 | ||||
-rw-r--r-- | lib/util/time.h | 3 | ||||
-rw-r--r-- | source3/lib/time.c | 2 | ||||
-rw-r--r-- | source3/param/loadparm.c | 2 |
5 files changed, 23 insertions, 5 deletions
diff --git a/lib/util/tests/time.c b/lib/util/tests/time.c index 4a31566b42..e24c5fe5ef 100644 --- a/lib/util/tests/time.c +++ b/lib/util/tests/time.c @@ -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); diff --git a/lib/util/time.c b/lib/util/time.c index a001e5f66e..eadafe4562 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -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) diff --git a/lib/util/time.h b/lib/util/time.h index 42644a3954..e40de2de3d 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -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_ */ diff --git a/source3/lib/time.c b/source3/lib/time.c index db2266fcbf..cae6b479b0 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -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. ****************************************************************************/ diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 8f03ae8fd7..274c79904e 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -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 { |