]> git.mxchange.org Git - flightgear.git/blob - src/Time/lowleveltime.h
Fiddling around with views, fdm data passing and management to try to be
[flightgear.git] / src / Time / lowleveltime.h
1 /* -*- Mode: C++ -*- *****************************************************
2  * lowleveltime.h
3  * Written by various people (I"ll look up the exact credits later)
4  * Modified by Durk Talsma, July 1999 for use in FlightGear
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  **************************************************************************/
21
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.                                        *
28  *                                                                  *
29  * Software adapted from glibc functions, by Durk Talsma. Started   *
30  * July, 17, 1999.                                                  *
31  ********************************************************************/
32
33 #ifndef _LOWLEVELTIME_H_
34 #define _LOWLEVELTIME_H_
35
36 #include <time.h>
37
38 /* adapted from zdump.c */
39 void show (const char *zone, time_t t, int v);
40
41 /* adapted from <time.h> */
42 struct tm * fgLocaltime (const time_t *t, const char *tzName);
43
44 /* Prototype for the internal function to get information based on TZ.  */
45 extern struct tm *fgtz_convert (const time_t *t, int use_localtime,
46                                      struct tm *tp, const char *tzName);
47
48 /* This structure contains all the information about a
49    timezone given in the POSIX standard TZ envariable.  */
50 typedef struct
51   {
52     const char *name;
53
54     /* When to change.  */
55     enum { J0, J1, M } type;    /* Interpretation of:  */
56     unsigned short int m, n, d; /* Month, week, day.  */
57     unsigned int secs;          /* Time of day.  */
58
59     long int offset;            /* Seconds east of GMT (west if < 0).  */
60
61     /* We cache the computed time of change for a
62        given year so we don't have to recompute it.  */
63     time_t change;      /* When to change to this zone.  */
64     int computed_for;   /* Year above is computed for.  */
65   } fgtz_rule;
66
67 /* tz_rules[0] is standard, tz_rules[1] is daylight.  */
68 static fgtz_rule fgtz_rules[2];
69
70 struct tzhead {
71         char    tzh_magic[4];           /* TZ_MAGIC */
72         char    tzh_reserved[16];       /* reserved for future use */
73         char    tzh_ttisgmtcnt[4];      /* coded number of trans. time flags */
74         char    tzh_ttisstdcnt[4];      /* coded number of trans. time flags */
75         char    tzh_leapcnt[4];         /* coded number of leap seconds */
76         char    tzh_timecnt[4];         /* coded number of transition times */
77         char    tzh_typecnt[4];         /* coded number of local time types */
78         char    tzh_charcnt[4];         /* coded number of abbr. chars */
79 };
80
81
82 /* Defined in mktime.c.  */
83 extern const unsigned short int mon_yday[2][13];
84
85 #ifndef TZDIR
86 #define TZDIR   "/usr/local/etc/zoneinfo" /* Time zone object file directory */
87 #endif /* !defined TZDIR */
88
89
90
91 #ifndef TZDEFAULT
92 #define TZDEFAULT       "localtime"
93 #endif /* !defined TZDEFAULT */
94
95 #define SECSPERMIN      60
96 #define MINSPERHOUR     60
97 #define HOURSPERDAY     24
98 #define DAYSPERWEEK     7
99 #define DAYSPERNYEAR    365
100 #define DAYSPERLYEAR    366
101 #define SECSPERHOUR     (SECSPERMIN * MINSPERHOUR)
102 #define SECSPERDAY      ((long) SECSPERHOUR * HOURSPERDAY)
103 #define MONSPERYEAR     12
104
105 #define TM_SUNDAY       0
106 #define TM_MONDAY       1
107 #define TM_TUESDAY      2
108 #define TM_WEDNESDAY    3
109 #define TM_THURSDAY     4
110 #define TM_FRIDAY       5
111 #define TM_SATURDAY     6
112
113 #define TM_JANUARY      0
114 #define TM_FEBRUARY     1
115 #define TM_MARCH        2
116 #define TM_APRIL        3
117 #define TM_MAY          4
118 #define TM_JUNE         5
119 #define TM_JULY         6
120 #define TM_AUGUST       7
121 #define TM_SEPTEMBER    8
122 #define TM_OCTOBER      9
123 #define TM_NOVEMBER     10
124 #define TM_DECEMBER     11
125
126 #define TM_YEAR_BASE    1900
127
128 #define EPOCH_YEAR      1970
129 #define EPOCH_WDAY      TM_THURSDAY
130
131 #endif