NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/57588: gmtime(3): value of %s depends on TZ environment variable



The following reply was made to PR lib/57588; it has been noted by GNATS.

From: Simon Gerraty <sjg%crufty.net@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: sjg%crufty.net@localhost
Subject: Re: lib/57588: gmtime(3): value of %s depends on TZ environment variable
Date: Sat, 19 Aug 2023 09:57:26 -0700

 The real problem is mktime(3) (which strtime(3) uses for %s)
 
 #include <sys/types.h>
 #include <stdio.h>
 #include <time.h>
 
 int
 main(void)
 {
 	time_t now;
 	time_t utime;
 	time_t ltime;
 
  	time(&now);
 	utime = mktime(gmtime(&now));
 	ltime = mktime(localtime(&now));
 
 	printf("now=\t\t%ld\ngmtime=\t\t%ld\nlocaltime=\t%ld\n",
 	       now, utime, ltime);
 	return 0;
 }
 
 utime and ltime should be the same as now, but
 utime is not:
 
 now=            1692464199
 gmtime=         1692492999
 localtime=      1692464199
 


Home | Main Index | Thread Index | Old Index