mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
Localtime: add a test main() function to check the output.
This commit is contained in:
parent
c25ee35a8b
commit
243c5a7a30
@ -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;
|
const time_t secs_day = 3600*24;
|
||||||
|
|
||||||
t -= tz; /* Adjust for timezone. */
|
t -= tz; /* Adjust for timezone. */
|
||||||
t += 3600+dst; /* Adjust for daylight time. */
|
|
||||||
time_t days = t / secs_day; /* Days passed since epoch. */
|
time_t days = t / secs_day; /* Days passed since epoch. */
|
||||||
time_t seconds = t % secs_day; /* Remaining seconds. */
|
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_mday = days+1; /* Add 1 since our 'days' is zero-based. */
|
||||||
tmp->tm_year -= 1900; /* Surprisingly tm_year is year-1900. */
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user