X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1d03fb9aeca8ed1d59e41b938629e9d9ff8f49bf..d43c995de90c5022b8a2be60e8595b0a968f6089:/sbr/dtime.c diff --git a/sbr/dtime.c b/sbr/dtime.c index 56d874e0..3f8f7631 100644 --- a/sbr/dtime.c +++ b/sbr/dtime.c @@ -5,10 +5,10 @@ * complete copyright information. */ -#include /* for snprintf() */ -#include -#include -#include +#include "h/mh.h" +#include "h/nmh.h" +#include "h/utils.h" +#include "h/tws.h" #include #if !defined(HAVE_STRUCT_TM_TM_GMTOFF) @@ -118,7 +118,7 @@ dlocaltime (time_t *clock) tw.tw_clock = *clock; - return (&tw); + return &tw; } @@ -165,7 +165,7 @@ dgmtime (time_t *clock) tw.tw_clock = *clock; - return (&tw); + return &tw; } @@ -285,7 +285,8 @@ dasctime (struct tws *tw, int flags) * return the string representation of the numeric offset. */ -char *dtimezone(int offset, int flags) +char * +dtimezone(int offset, int flags) { static char buffer[sizeof "+3579139459"]; /* 2,147,483,648 / 60 = 35,791,394 */ bool pos; @@ -345,14 +346,17 @@ dmktime (struct tws *tw) while (--mon) result += dmsize[mon - 1]; result += mday - 1; - result = 24 * result + hour; - result = 60 * result + min; - result = 60 * result + sec; + result *= 24; /* Days to hours. */ + result += hour; + result *= 60; /* Hours to minutes. */ + result += min; + result *= 60; /* Minutes to seconds. */ + result += sec; result -= 60 * tw->tw_zone; if (tw->tw_flags & TW_DST) - result -= 60 * 60; + result -= 60 * 60; /* One hour. */ - return (tw->tw_clock = result); + return tw->tw_clock = result; } @@ -405,6 +409,6 @@ twsort (struct tws *tw1, struct tws *tw2) if (tw2->tw_clock == 0) dmktime (tw2); - return ((c1 = tw1->tw_clock) > (c2 = tw2->tw_clock) ? 1 - : c1 == c2 ? 0 : -1); + return (c1 = tw1->tw_clock) > (c2 = tw2->tw_clock) ? 1 + : c1 == c2 ? 0 : -1; }