summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-07-04 13:46:27 +0200
committerantirez <antirez@gmail.com>2018-07-04 13:46:31 +0200
commit243c5a7a305eaf7a7cf936eb6805f44f9802b3a5 (patch)
tree707c6449928947da5c5d8d4d29b66aa26f024992
parentc25ee35a8b6bcabab615e7babe486b08eebc9a47 (diff)
downloadredis-243c5a7a305eaf7a7cf936eb6805f44f9802b3a5.tar.gz
Localtime: add a test main() function to check the output.
-rw-r--r--src/localtime.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/localtime.c b/src/localtime.c
index a92248ecb..c3564d1b0 100644
--- a/src/localtime.c
+++ b/src/localtime.c
@@ -57,7 +57,6 @@ void nolocks_localtime(struct tm *tmp, time_t t, time_t tz, int dst) {
const time_t secs_day = 3600*24;
t -= tz; /* Adjust for timezone. */
- t += 3600+dst; /* Adjust for daylight time. */
time_t days = t / secs_day; /* Days passed since epoch. */
time_t seconds = t % secs_day; /* Remaining seconds. */
@@ -97,3 +96,18 @@ void nolocks_localtime(struct tm *tmp, time_t t, time_t tz, int dst) {
tmp->tm_mday = days+1; /* Add 1 since our 'days' is zero-based. */
tmp->tm_year -= 1900; /* Surprisingly tm_year is year-1900. */
}
+
+#ifdef LOCALTIME_TEST_MAIN
+#include <stdio.h>
+
+int main(void) {
+ tzset();
+ time_t t = time(NULL);
+ struct tm tm;
+ char buf[1024];
+
+ nolocks_localtime(&tm,t,timezone,daylight);
+ strftime(buf,sizeof(buf),"%d %b %H:%M:%S",&tm);
+ printf("[timezone: %d, dl: %d] %s\n", (int)timezone, (int)daylight, buf);
+}
+#endif