00001 /* -*- Mode: C++ -*- ***************************************************** 00002 * lowleveltime.h 00003 * Written by various people (I"ll look up the exact credits later) 00004 * Modified by Durk Talsma, July 1999 for use in FlightGear 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 **************************************************************************/ 00021 00022 /******************************************************************** 00023 * This file redefines some low-level Unix-like time functions for * 00024 * use with FlightGear. Most notably, localtime() is adapted to use * 00025 * a custom timezone, in order to get the 'local' time for a given * 00026 * aircraft's position, and not only for the current location of the* 00027 * computer running the sim. * 00028 * * 00029 * Software adapted from glibc functions, by Durk Talsma. Started * 00030 * July, 17, 1999. * 00031 ********************************************************************/ 00032 00033 #ifndef _LOWLEVELTIME_H_ 00034 #define _LOWLEVELTIME_H_ 00035 00036 #include <time.h> 00037 00038 /* adapted from zdump.c */ 00039 void show (const char *zone, time_t t, int v); 00040 00041 /* adapted from <time.h> */ 00042 struct tm * fgLocaltime (const time_t *t, const char *tzName); 00043 00044 /* Prototype for the internal function to get information based on TZ. */ 00045 extern struct tm *fgtz_convert (const time_t *t, int use_localtime, 00046 struct tm *tp, const char *tzName); 00047 00048 /* This structure contains all the information about a 00049 timezone given in the POSIX standard TZ envariable. */ 00050 typedef struct 00051 { 00052 const char *name; 00053 00054 /* When to change. */ 00055 enum { J0, J1, M } type; /* Interpretation of: */ 00056 unsigned short int m, n, d; /* Month, week, day. */ 00057 unsigned int secs; /* Time of day. */ 00058 00059 long int offset; /* Seconds east of GMT (west if < 0). */ 00060 00061 /* We cache the computed time of change for a 00062 given year so we don't have to recompute it. */ 00063 time_t change; /* When to change to this zone. */ 00064 int computed_for; /* Year above is computed for. */ 00065 } fgtz_rule; 00066 00067 struct tzhead { 00068 char tzh_magic[4]; /* TZ_MAGIC */ 00069 char tzh_reserved[16]; /* reserved for future use */ 00070 char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ 00071 char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ 00072 char tzh_leapcnt[4]; /* coded number of leap seconds */ 00073 char tzh_timecnt[4]; /* coded number of transition times */ 00074 char tzh_typecnt[4]; /* coded number of local time types */ 00075 char tzh_charcnt[4]; /* coded number of abbr. chars */ 00076 }; 00077 00078 00079 /* Defined in mktime.c. */ 00080 extern const unsigned short int mon_yday[2][13]; 00081 00082 #ifndef TZDIR 00083 #define TZDIR "/usr/local/etc/zoneinfo" /* Time zone object file directory */ 00084 #endif /* !defined TZDIR */ 00085 00086 00087 00088 #ifndef TZDEFAULT 00089 #define TZDEFAULT "localtime" 00090 #endif /* !defined TZDEFAULT */ 00091 00092 #define SECSPERMIN 60 00093 #define MINSPERHOUR 60 00094 #define HOURSPERDAY 24 00095 #define DAYSPERWEEK 7 00096 #define DAYSPERNYEAR 365 00097 #define DAYSPERLYEAR 366 00098 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) 00099 #define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY) 00100 #define MONSPERYEAR 12 00101 00102 #define TM_SUNDAY 0 00103 #define TM_MONDAY 1 00104 #define TM_TUESDAY 2 00105 #define TM_WEDNESDAY 3 00106 #define TM_THURSDAY 4 00107 #define TM_FRIDAY 5 00108 #define TM_SATURDAY 6 00109 00110 #define TM_JANUARY 0 00111 #define TM_FEBRUARY 1 00112 #define TM_MARCH 2 00113 #define TM_APRIL 3 00114 #define TM_MAY 4 00115 #define TM_JUNE 5 00116 #define TM_JULY 6 00117 #define TM_AUGUST 7 00118 #define TM_SEPTEMBER 8 00119 #define TM_OCTOBER 9 00120 #define TM_NOVEMBER 10 00121 #define TM_DECEMBER 11 00122 00123 #define TM_YEAR_BASE 1900 00124 00125 #define EPOCH_YEAR 1970 00126 #define EPOCH_WDAY TM_THURSDAY 00127 00128 #endif