| Summary: | mktime() fails (returns -1) on some dates. | ||
|---|---|---|---|
| Product: | Base System | Reporter: | duwde <duwde> |
| Component: | misc | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 2.2.8-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
On Mon, Sep 20, 1999 at 10:23:10AM -0700, duwde@elitenet.com.br wrote: > > >How-To-Repeat: > /* > Try this, there seems to be a problem in mktime(), using 2.2.8-RELEASE. > mktime() doesn't work when using dates like (day/month/year): > 03/10/1999 - 16/10/1994 - and others... > > Duwde <duwde@elitenet.com.br> > */ % uname -v FreeBSD 2.2.8-RELEASE #2: Wed Dec 23 20:01:04 EET 1998 root@relay.fil05.ucb.crimea.ua:/usr/src/sys/compile/FIL05 % ./a everything is ok... It works on 2.2.1-RELEASE and 3.2-STABLE boxes as well. Any additional info? -- Ruslan Ermilov Sysadmin and DBA of the ru@ucb.crimea.ua United Commercial Bank, ru@FreeBSD.org FreeBSD committer, +380.652.247.647 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age <<On Mon, 20 Sep 1999 22:27:29 +0200, Fabio Dias <duwde@elitenet.com.br> said: > My timezone is America -> Brazil -> SE ! (EST) The fact that your problem is timezone-dependent should have given you a clue. The time you have specified (midnight) does not exist in your timezone on that date, due to the switch over to (or from) summer time. Thus, mktime() is correct to return an error. If you retry your request with tm_isdst set to -1, mktime() will attempt to guess whether you mean standard time or summer (daylight savings) time -- but there are still times which are impossible to resolve. Most other countries switch at times other than midnight. You might find the results less surprising if you updated your timezone files to more recent ones which reflect the latest legal time changes in Brazil. In sum: there is no bug here. -GAWollman State Changed From-To: open->closed Known timezone-related issue. |
When using some specific dates, mktimes() is unable to return the real time_t and returns -1. Fix: Fix the mktime() How-To-Repeat: /* Try this, there seems to be a problem in mktime(), using 2.2.8-RELEASE. mktime() doesn't work when using dates like (day/month/year): 03/10/1999 - 16/10/1994 - and others... Duwde <duwde@elitenet.com.br> */ #include <stdio.h> #include <time.h> #include <string.h> int main(int argc, char **argv) { time_t timet_x; struct tm tm_x, *tm_px=&tm_x; memset(tm_px,(int)NULL,sizeof(tm_x)); tm_px->tm_mday=3; /* 03 */ tm_px->tm_mon=9; /* 10 */ tm_px->tm_year=99; /* 1999 */ if ((timet_x=mktime(tm_px)) == -1) { printf("mktime() returned -1\n"); printf("asctime(tm_px) -> %s\n",asctime(tm_px)); printf("ctime(&timet_x) -> %s\n",ctime(&timet_x)); } else printf("everything is ok...\n"); return (int)0;