3 * Data structures and routines for managing time related values.
6 // Written by Curtis Olson, started August 1997.
8 // Copyright (C) 1997 Curtis L. Olson - curt@flightgear.org
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Library General Public License for more details.
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
33 # error This library requires C++
41 #include <simgear/compiler.h>
43 #ifdef SG_HAVE_STD_INCLUDES
49 #include <simgear/timing/timezone.h>
53 * A class to calculate and manage a variety of time parameters.
59 // tzContainer stores all the current Timezone control points/
60 TimezoneContainer* tzContainer;
62 // Points to the current local timezone name;
65 // Unix "calendar" time in seconds
68 // Break down of equivalent GMT time
71 // offset of local time relative to GMT
77 // modified Julian date
80 // side real time at prime meridian
83 // local sidereal time
86 // the difference between the precise / expensive sidereal time
87 // algorithm result and the quick course result. course_gst +
88 // gst_diff has pretty good accuracy over the span of a couple hours
93 /** Default constructor */
97 * Create an instance based on a specified position and data file path.
98 * @param lon current longitude
99 * @param lat current latitude
100 * @param root root path point to data file location (timezone, etc.)
102 SGTime( double lon, double lat, const string& root );
105 * Create an instance given a data file path
106 * @param root root path point to data file location (timezone, etc.)
108 SGTime( const string& root );
114 * Update the time related variables.
115 * @param lon current longitude
116 * @param lat current latitude
117 * @param warp an optional time offset specified in seconds. This
118 * allows us to advance or rewind "time" if we choose to.
120 void update( double lon, double lat, long int warp = 0 );
122 // Given lon/lat, update timezone information and local_offset
123 void updateLocal( double lon, double lat, const string& root );
125 inline time_t get_cur_time() const { return cur_time; };
126 inline char* get_zonename() const { return zonename; }
127 inline struct tm* getGmt()const { return gmt; };
128 inline double getJD() const { return jd; };
129 inline double getMjd() const { return mjd; };
130 inline double getLst() const { return lst; };
131 inline double getGst() const { return gst; };
135 // Some useful utility functions that don't make sense to be part of
138 // Return unix time in seconds for the given data (relative to GMT)
139 time_t sgTimeGetGMT(int year, int month, int day,
140 int hour, int minute, int second);
142 // this is just a wrapper
143 inline time_t sgTimeGetGMT(struct tm* the_time) {
144 // printf("Using: %24s as input\n", asctime(the_time));
145 return sgTimeGetGMT(the_time->tm_year,
153 // given a date in months, mn, days, dy, years, yr, return the
154 // modified Julian date (number of days elapsed since 1900 jan 0.5),
155 // mjd. Adapted from Xephem.
156 double sgTimeCalcMJD(int mn, double dy, int yr);
158 // given an mjd, calculate greenwich mean sidereal time, gst
159 double sgTimeCalcGST( double mjd );
162 char* sgTimeFormatTime( const struct tm* p, char* buf );
165 #endif // _SG_TIME_HXX