home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
pd8.lzh
/
SRC
/
time.c
< prev
next >
Wrap
Text File
|
1990-05-04
|
2KB
|
120 lines
/* get the time from the os.
*
* here are two methods I was able to verify; pick one for your system and
* define exactly one of TZA or TZB:
* TZA works on our ibm-pc/turbo-c and at&t systems,
* TZB works on our 4.2 BSD vax.
*
* I'm told that on Sun OS 4.0.3 (BSD 4.3?) and Apollo SR 10.1 TZB works if
* you use <sys/time.h> in place of <time.h>.
*/
#ifndef OSK
#define TZA
#endif
#include <stdio.h>
#include <time.h>
#include "astro.h"
#include "circum.h"
extern char *strncpy();
extern long time();
static long c0;
static double mjd0;
/* save current mjd and corresponding system clock for use by inc_mjd().
* this establishes the base correspondence between the mjd and system clock.
*/
set_t0 (np)
Now *np;
{
mjd0 = mjd;
time (&c0);
}
/* fill in n_mjd/tz/tznm from system clock.
*/
time_fromsys (np)
Now *np;
{
extern struct tm *gmtime(), *localtime();
struct tm *tp;
long c;
double day, hr;
time (&c);
tp = localtime (&c);
settzstuff (tp->tm_isdst ? 1 : 0, np);
/* N.B. gmtime() can return pointer to same area as localtime(), ie,
* reuse the same static area, so be sure to call it after we are
* through with local time info.
*/
tp = gmtime (&c);
cal_mjd (tp->tm_mon+1, (double)tp->tm_mday, tp->tm_year+1900, &day);
sex_dec (tp->tm_hour, tp->tm_min, tp->tm_sec, &hr);
mjd = day + hr/24.0;
}
/* given whether dst is now in effect (must be strictly 0 or 1), fill in
* tzname and tz within np.
*/
static
settzstuff (dst, np)
int dst;
Now *np;
{
#ifdef TZA
extern long timezone;
extern char *tzname[2];
tzset();
tz = timezone/3600;
if (dst)
tz -= 1.0;
strncpy (tznm, tzname[dst], sizeof(tznm)-1);
#endif
#ifdef TZB
extern char *timezone();
struct timeval timev;
struct timezone timez;
gettimeofday (&timev, &timez);
tz = timez.tz_minuteswest/60;
if (dst)
tz -= 1.0;
strncpy (tznm, timezone(timez.tz_minuteswest, dst), sizeof(tznm)-1);
#endif
#ifdef OSK
char *tzenv = (char *) getenv("TZ");
static char first = 1;
if (dst && first)
tz -= 1.0;
first = 0;
strncpy (tznm,tzenv ? tzenv : "",3);
#endif
tznm[sizeof(tznm)-1] = '\0'; /* insure string is terminated */
}
inc_mjd (np, inc)
Now *np;
double inc;
{
if (inc == RTC) {
long c;
time (&c);
mjd = mjd0 + (c - c0)/SPD;
} else
mjd += inc/24.0;
/* round to nearest whole second.
* without this, you can get fractional days so close to .5 but
* not quite there that mjd_hr() can return 24.0
*/
rnd_second (&mjd);
}