]> git.mxchange.org Git - simgear.git/blob - simgear/timing/lowleveltime.h
SG-ified logstream.
[simgear.git] / simgear / timing / 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 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.
10  *
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.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA  02111-1307, USA.
20  *
21  **************************************************************************/
22
23 /********************************************************************
24  * This file redefines some low-level Unix-like time functions for  *
25  * use with FlightGear. Most notably, localtime() is adapted to use *
26  * a custom timezone, in order to get the 'local' time for a given  *
27  * aircraft's position, and not only for the current location of the*
28  * computer running the sim.                                        *
29  *                                                                  *
30  * Software adapted from glibc functions, by Durk Talsma. Started   *
31  * July, 17, 1999.                                                  *
32  ********************************************************************/
33
34 #ifndef _LOWLEVELTIME_H_
35 #define _LOWLEVELTIME_H_
36
37 #include <time.h>
38
39 /* adapted from zdump.c */
40 void show (const char *zone, time_t t, int v);
41
42 /* adapted from <time.h> */
43 struct tm * fgLocaltime (const time_t *t, const char *tzName);
44
45 /* Prototype for the internal function to get information based on TZ.  */
46 extern struct tm *fgtz_convert (const time_t *t, int use_localtime,
47                                      struct tm *tp, const char *tzName);
48
49 /* This structure contains all the information about a
50    timezone given in the POSIX standard TZ envariable.  */
51 typedef struct
52   {
53     const char *name;
54
55     /* When to change.  */
56     enum { J0, J1, M } type;    /* Interpretation of:  */
57     unsigned short int m, n, d; /* Month, week, day.  */
58     unsigned int secs;          /* Time of day.  */
59
60     long int offset;            /* Seconds east of GMT (west if < 0).  */
61
62     /* We cache the computed time of change for a
63        given year so we don't have to recompute it.  */
64     time_t change;      /* When to change to this zone.  */
65     int computed_for;   /* Year above is computed for.  */
66   } fgtz_rule;
67
68 struct tzhead {
69         char    tzh_magic[4];           /* TZ_MAGIC */
70         char    tzh_reserved[16];       /* reserved for future use */
71         char    tzh_ttisgmtcnt[4];      /* coded number of trans. time flags */
72         char    tzh_ttisstdcnt[4];      /* coded number of trans. time flags */
73         char    tzh_leapcnt[4];         /* coded number of leap seconds */
74         char    tzh_timecnt[4];         /* coded number of transition times */
75         char    tzh_typecnt[4];         /* coded number of local time types */
76         char    tzh_charcnt[4];         /* coded number of abbr. chars */
77 };
78
79
80 /* Defined in mktime.c.  */
81 extern const unsigned short int mon_yday[2][13];
82
83 #ifndef TZDIR
84 #define TZDIR   "/usr/local/etc/zoneinfo" /* Time zone object file directory */
85 #endif /* !defined TZDIR */
86
87
88
89 #ifndef TZDEFAULT
90 #define TZDEFAULT       "localtime"
91 #endif /* !defined TZDEFAULT */
92
93 #define SECSPERMIN      60
94 #define MINSPERHOUR     60
95 #define HOURSPERDAY     24
96 #define DAYSPERWEEK     7
97 #define DAYSPERNYEAR    365
98 #define DAYSPERLYEAR    366
99 #define SECSPERHOUR     (SECSPERMIN * MINSPERHOUR)
100 #define SECSPERDAY      ((long) SECSPERHOUR * HOURSPERDAY)
101 #define MONSPERYEAR     12
102
103 #define TM_SUNDAY       0
104 #define TM_MONDAY       1
105 #define TM_TUESDAY      2
106 #define TM_WEDNESDAY    3
107 #define TM_THURSDAY     4
108 #define TM_FRIDAY       5
109 #define TM_SATURDAY     6
110
111 #define TM_JANUARY      0
112 #define TM_FEBRUARY     1
113 #define TM_MARCH        2
114 #define TM_APRIL        3
115 #define TM_MAY          4
116 #define TM_JUNE         5
117 #define TM_JULY         6
118 #define TM_AUGUST       7
119 #define TM_SEPTEMBER    8
120 #define TM_OCTOBER      9
121 #define TM_NOVEMBER     10
122 #define TM_DECEMBER     11
123
124 #define TM_YEAR_BASE    1900
125
126 #define EPOCH_YEAR      1970
127 #define EPOCH_WDAY      TM_THURSDAY
128
129 #endif