Date: Fri, 6 Jan 2006 01:24:42 +0100 (CET) From: "Frank W. Josellis" <frank@dynamical-systems.org> To: FreeBSD-gnats-submit@FreeBSD.org Cc: josh@tcbug.org Subject: ports/91368: astro/xephem - Proposal for fixing xephem's time conversion to cope with leap seconds Message-ID: <200601060024.k060Ogbd002792@pollux.senax.net> Resent-Message-ID: <200601060050.k060o3RF052707@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 91368 >Category: ports >Synopsis: astro/xephem - Proposal for fixing xephem's time conversion to cope with leap seconds >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Jan 06 00:50:02 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Frank W. Josellis >Release: FreeBSD 5.4-STABLE i386 >Organization: >Environment: System: FreeBSD pollux.senax.net 5.4-STABLE FreeBSD 5.4-STABLE #2: Tue Dec 20 16:37:59 CET 2005 root@pollux.senax.net:/usr/obj/usr/src/sys/POLLUX i386 >Description: Xephem provides routines to convert between the astronomical MJD time scale and civil date formats (UTC, local time). These conversions silently assume that 1 second equals 1/86400 of a day (so that, strictly speaking, MJD is actually related to UT1 rather than UTC). Without having to think too much about all this, everything looks fine as long as the system's zoneinfo files were built conforming to POSIX, i.e., without support for UTC leap seconds. If, however, the system was configured for true UTC, its idea of the current time differs from what is displayed by xephem. Moreover, xephem's attempt to derive the local time may fail to give the correct result and one obtains odd TZ offset values. Please consider the patch below which enables consistent time conversions even without requiring POSIX-style zoneinfo files. NOTE 1: My patch adds the following files: files/patch-time.c files/patch-tools_lx200xed_Makefile files/patch-tools_lx200xed_lx200xed.c NOTE 2: In my patch, the idea of compiling with -D_BSD_SOURCE may look somewhat clumsy. The reason is that this strategy would also allow to use the patch with glibc, so it's slightly more general than required for a FreeBSD port. >How-To-Repeat: To see the effects described above, build the zoneinfo files with support for leap seconds: cd /usr/src/share/zoneinfo make -DLEAPSECONDS clean all install ; make clean and update /etc/localtime (repeat these steps without the -DLEAPSECONDS flag to regain POSIX-style zoneinfo files). Then run xephem and watch the time information in the control panel. >Fix: --- xephem-3.7.1.patch begins here --- diff -Nur xephem.BAK/Makefile xephem/Makefile --- xephem.BAK/Makefile Sat Dec 10 03:04:26 2005 +++ xephem/Makefile Thu Jan 5 16:20:47 2006 @@ -54,10 +54,11 @@ pre-install: @${FIND} ${WRKSRC}/../.. -name Makefile.bak -type f | ${XARGS} ${RM} -f + @${FIND} ${WRKSRC}/tools -name "*.orig" -type f | ${XARGS} ${RM} -f do-install: ${INSTALL_PROGRAM} ${WRKSRC}/xephem ${PREFIX}/bin - ${INSTALL_MAN} ${WRKSRC}/xephem.1 ${PREFIX}/man/man1 + ${INSTALL_MAN} ${WRKSRC}/xephem.1 ${PREFIX}/man/man1 ${INSTALL_DATA} ${WRKSRC}/XEphem.ad ${PREFIX}/lib/X11/app-defaults/XEphem @${MKDIR} ${PREFIX}/lib/X11/xephem ${TAR} -C ${WRKSRC} -cf - auxil catalogs fifos fits gallery help lo tools \ diff -Nur xephem.BAK/files/patch-Makefile xephem/files/patch-Makefile --- xephem.BAK/files/patch-Makefile Sat Dec 10 03:04:26 2005 +++ xephem/files/patch-Makefile Thu Jan 5 16:20:47 2006 @@ -1,5 +1,5 @@ ---- Makefile.orig Fri Nov 18 16:43:09 2005 -+++ Makefile Mon Dec 5 12:58:21 2005 +--- Makefile.orig Fri Nov 18 14:42:47 2005 ++++ Makefile Wed Jan 4 14:14:44 2006 @@ -10,9 +10,9 @@ # back here and compile and link all the *.c files into one executable, xephem. @@ -13,15 +13,17 @@ # MOTIFI is the directory containing the Xm directory of include files. # MOTIFL is the directory containing the libXm.a library. -@@ -31,7 +31,7 @@ +@@ -31,8 +31,8 @@ # for linux and Apple OS X CC = gcc -CLDFLAGS = -g +-CFLAGS = $(LIBINC) $(CLDFLAGS) -O2 -Wall -I$(MOTIFI) -I/usr/X11R6/include +#CLDFLAGS = -g - CFLAGS = $(LIBINC) $(CLDFLAGS) -O2 -Wall -I$(MOTIFI) -I/usr/X11R6/include ++CFLAGS = $(LIBINC) $(CLDFLAGS) -O2 -Wall -D_BSD_SOURCE -I$(MOTIFI) -I/usr/X11R6/include LDFLAGS = $(LIBLNK) $(CLDFLAGS) -L$(MOTIFL) -L/usr/X11R6/lib XLIBS = $(MOTIFL)/libXm.a -lXp -lXt -lXext -lSM -lICE -lXmu -lX11 + LIBS = $(XLIBS) $(LIBLIB) -lm @@ -181,10 +181,7 @@ libs: cd ../../libastro; make diff -Nur xephem.BAK/files/patch-time.c xephem/files/patch-time.c --- xephem.BAK/files/patch-time.c Thu Jan 1 01:00:00 1970 +++ xephem/files/patch-time.c Thu Jan 5 16:20:47 2006 @@ -0,0 +1,52 @@ +--- time.c.orig Sat Jul 9 04:11:48 2005 ++++ time.c Wed Jan 4 14:14:44 2006 +@@ -32,7 +32,8 @@ + time_fromsys (np) + Now *np; + { +- time_t t; ++ time_t t, s; ++ struct tm *gm; + + t = time(NULL); + +@@ -50,7 +51,22 @@ + */ + mjd = (25567.5 + t/3600.0/24.0) + (tz/24.0); + #else +- mjd = 25567.5 + t/3600.0/24.0; ++ /* Get seconds since the EPOCH according to POSIX, i.e., without ++ * UTC leap seconds. A consistent conversion MJD <-> UTC requires ++ * here that a second be 1/86400 of a day, which, of course, is ++ * not identical to the SI second from the UTC time scale! ++ */ ++ gm = gmtime(&t); ++ s = gm->tm_sec ++ + gm->tm_min * 60 ++ + gm->tm_hour * 3600 ++ + gm->tm_yday * 86400 ++ + (gm->tm_year - 70) * 31536000 ++ + ((gm->tm_year - 69)/4) * 86400 ++ - ((gm->tm_year - 1)/100) * 86400 ++ + ((gm->tm_year + 299)/400) * 86400; ++ ++ mjd = 25567.5 + s/3600.0/24.0; + #endif + + (void) tz_fromsys(np); +@@ -93,10 +109,15 @@ + gmkt = (double) mktime (gtmp); + + ltmp = localtime (&t); ++ ++#ifdef _BSD_SOURCE ++ tz = -ltmp->tm_gmtoff / 3600.0; ++#else + ltmp->tm_isdst = 0; /* let mktime() figure out zone */ + lmkt = (double) mktime (ltmp); + + tz = (gmkt - lmkt) / 3600.0; ++#endif + (void) strftime (tznm, sizeof(tznm)-1, "%Z", ltmp); + return (0); + } else diff -Nur xephem.BAK/files/patch-tools_lx200xed_Makefile xephem/files/patch-tools_lx200xed_Makefile --- xephem.BAK/files/patch-tools_lx200xed_Makefile Thu Jan 1 01:00:00 1970 +++ xephem/files/patch-tools_lx200xed_Makefile Thu Jan 5 16:20:47 2006 @@ -0,0 +1,10 @@ +--- tools/lx200xed/Makefile.orig Sun Mar 20 12:04:29 2005 ++++ tools/lx200xed/Makefile Wed Jan 4 14:49:30 2006 +@@ -1,6 +1,6 @@ + LIBASTRO = ../../../../libastro + CLDFLAGS = +-CFLAGS = -Wall -O2 $(CLDFLAGS) -I$(LIBASTRO) ++CFLAGS = -Wall -O2 -D_BSD_SOURCE $(CLDFLAGS) -I$(LIBASTRO) + LDFLAGS = $(CLDFLAGS) -L$(LIBASTRO) + CC = gcc + diff -Nur xephem.BAK/files/patch-tools_lx200xed_lx200xed.c xephem/files/patch-tools_lx200xed_lx200xed.c --- xephem.BAK/files/patch-tools_lx200xed_lx200xed.c Thu Jan 1 01:00:00 1970 +++ xephem/files/patch-tools_lx200xed_lx200xed.c Thu Jan 5 16:20:47 2006 @@ -0,0 +1,56 @@ +--- tools/lx200xed/lx200xed.c.orig Sun Mar 20 12:04:29 2005 ++++ tools/lx200xed/lx200xed.c Wed Jan 4 14:14:44 2006 +@@ -575,10 +575,12 @@ + time_fromsys (Now *np) + { + #if defined(__STDC__) +- time_t t; ++ time_t; + #else + long t; + #endif ++ time_t s; ++ struct tm *gm; + + trace(6,"In time_fromsys...\n",NULL); + +@@ -598,7 +600,22 @@ + */ + mjd = (25567.5 + t/3600.0/24.0) + (tz/24.0); + #else +- mjd = 25567.5 + t/3600.0/24.0; ++ /* Get seconds since the EPOCH according to POSIX, i.e., without ++ * UTC leap seconds. A consistent conversion MJD <-> UTC requires ++ * here that a second be 1/86400 of a day, which, of course, is ++ * not identical to the SI second from the UTC time scale! ++ */ ++ gm = gmtime(&t); ++ s = gm->tm_sec ++ + gm->tm_min * 60 ++ + gm->tm_hour * 3600 ++ + gm->tm_yday * 86400 ++ + (gm->tm_year - 70) * 31536000 ++ + ((gm->tm_year - 69)/4) * 86400 ++ - ((gm->tm_year - 1)/100) * 86400 ++ + ((gm->tm_year + 299)/400) * 86400; ++ ++ mjd = 25567.5 + s/3600.0/24.0; + #endif + snprintf(szMsg,100,"TFS: %f\n",mjd); + trace(5,szMsg,NULL); +@@ -637,10 +654,15 @@ + gmkt = (double) mktime (gtmp); + + ltmp = localtime (&t); ++ ++#ifdef _BSD_SOURCE ++ tz = -ltmp->tm_gmtoff / 3600.0; ++#else + ltmp->tm_isdst = 0; /* let mktime() figure out zone */ + lmkt = (double) mktime (ltmp); + + tz = (gmkt - lmkt) / 3600.0; ++#endif + (void) strftime (tznm, sizeof(tznm)-1, "%Z", ltmp); + return (0); + } else --- xephem-3.7.1.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200601060024.k060Ogbd002792>