1 /* -*- Mode: C++ -*- *****************************************************
3 * Written by various people (I"ll look up the exact credits later)
4 * Modified by Durk Talsma, July 1999 for use in FlightGear
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 **************************************************************************/
22 /********************************************************************
23 * This file redefines some low-level Unix-like time functions for *
24 * use with FlightGear. Most notably, localtime() is adapted to use *
25 * a custom timezone, in order to get the 'local' time for a given *
26 * aircraft's position, and not only for the current location of the*
27 * computer running the sim. *
29 * Software adapted from glibc functions, by Durk Talsma. Started *
31 ********************************************************************/
33 #ifndef _LOWLEVELTIME_H_
34 #define _LOWLEVELTIME_H_
38 /* adapted from zdump.c */
39 void show (const char *zone, time_t t, int v);
41 /* adapted from <time.h> */
42 struct tm * fgLocaltime (const time_t *t, const char *tzName);
44 /* version of time() which returns a value in GMT/UTC, without
45 any timezone adjustment. Necessary on Windows where calling time()
46 returns a value in the local time-zone. */
49 /* Prototype for the internal function to get information based on TZ. */
50 extern struct tm *fgtz_convert (const time_t *t, int use_localtime,
51 struct tm *tp, const char *tzName);
53 /* This structure contains all the information about a
54 timezone given in the POSIX standard TZ envariable. */
60 enum { J0, J1, M } type; /* Interpretation of: */
61 unsigned short int m, n, d; /* Month, week, day. */
62 unsigned int secs; /* Time of day. */
64 long int offset; /* Seconds east of GMT (west if < 0). */
66 /* We cache the computed time of change for a
67 given year so we don't have to recompute it. */
68 time_t change; /* When to change to this zone. */
69 int computed_for; /* Year above is computed for. */
73 char tzh_magic[4]; /* TZ_MAGIC */
74 char tzh_reserved[16]; /* reserved for future use */
75 char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
76 char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
77 char tzh_leapcnt[4]; /* coded number of leap seconds */
78 char tzh_timecnt[4]; /* coded number of transition times */
79 char tzh_typecnt[4]; /* coded number of local time types */
80 char tzh_charcnt[4]; /* coded number of abbr. chars */
84 /* Defined in mktime.c. */
85 extern const unsigned short int mon_yday[2][13];
88 #define TZDIR "/usr/local/etc/zoneinfo" /* Time zone object file directory */
89 #endif /* !defined TZDIR */
94 #define TZDEFAULT "localtime"
95 #endif /* !defined TZDEFAULT */
98 #define MINSPERHOUR 60
99 #define HOURSPERDAY 24
100 #define DAYSPERWEEK 7
101 #define DAYSPERNYEAR 365
102 #define DAYSPERLYEAR 366
103 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
104 #define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
105 #define MONSPERYEAR 12
110 #define TM_WEDNESDAY 3
111 #define TM_THURSDAY 4
113 #define TM_SATURDAY 6
116 #define TM_FEBRUARY 1
123 #define TM_SEPTEMBER 8
125 #define TM_NOVEMBER 10
126 #define TM_DECEMBER 11
128 #define TM_YEAR_BASE 1900
130 #define EPOCH_YEAR 1970
131 #define EPOCH_WDAY TM_THURSDAY