1 // sg_time.hxx -- data structures and routines for managing time related stuff.
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 # error This library requires C++
43 #include <simgear/compiler.h>
45 #ifdef FG_HAVE_STD_INCLUDES
51 // #include <FDM/flight.hxx>
54 // #include "lowleveltime.h"
57 enum sgTimingOffsetType {
58 SG_TIME_SYS_OFFSET = 0,
59 SG_TIME_GMT_OFFSET = 1,
60 SG_TIME_LAT_OFFSET = 2,
61 SG_TIME_SYS_ABSOLUTE = 3,
62 SG_TIME_GMT_ABSOLUTE = 4,
63 SG_TIME_LAT_ABSOLUTE = 5
67 // Define a structure containing time parameters
71 // tzContainer stores all the current Timezone control points/
72 TimezoneContainer* tzContainer;
74 //Store the current local timezone name;
77 // Unix "calendar" time in seconds
80 // Break down of GMT time
86 // modified Julian date
89 double last_mjd, last_dy;
92 // side real time at prime meridian
95 // local sidereal time
98 // local offset to GMT
101 // the difference between the precise sidereal time algorithm
102 // result and the course result. course + diff has good accuracy
103 // for the short term
106 // An offset in seconds from the true time. Allows us to adjust
107 // the effective time of day.
110 // How much to change the value of warp each iteration. Allows us
111 // to make time progress faster than normal.
116 SGTime( const string& root );
119 inline double getJD() const { return jd; };
120 inline double getMjd() const { return mjd; };
121 inline double getLst() const { return lst; };
122 inline double getGst() const { return gst; };
123 inline time_t get_cur_time() const { return cur_time; };
124 inline struct tm* getGmt()const { return gmt; };
126 void adjust_warp(int val) { warp += val; };
127 void adjust_warp_delta(int val) { warp_delta += val; };
129 // Initialize the time dependent variables
130 void init( double lon, double lat, const string& root,
131 time_t timeOffset, sgTimingOffsetType offsetType );
133 // Update the time dependent variables
134 void update( double lon, double lat, double alt_m );
135 void updateLocal( double lon, double lat, const string& root );
137 void cal_mjd (int mn, double dy, int yr);
139 double sidereal_precise (double lng);
140 double sidereal_course(double lng);
141 static SGTime *cur_time_params;
143 // Some other stuff which were changed to SGTime members on
144 // questionable grounds -:)
145 // time_t get_start_gmt(int year);
146 time_t get_gmt(int year, int month, int day,
147 int hour, int minute, int second);
148 time_t get_gmt(struct tm* the_time);
150 char* format_time( const struct tm* p, char* buf );
151 long int fix_up_timezone( long int timezone_orig );
153 inline int get_warp_delta() const { return warp_delta; }
157 inline time_t SGTime::get_gmt(struct tm* the_time) // this is just a wrapper
159 //printf("Using: %24s as input\n", asctime(the_time));
160 return get_gmt(the_time->tm_year,
169 #endif // _SG_TIME_HXX