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++
37 #include <simgear/compiler.h>
39 #ifdef FG_HAVE_STD_INCLUDES
48 // Define a structure containing time parameters
52 // tzContainer stores all the current Timezone control points/
53 TimezoneContainer* tzContainer;
55 // Points to the current local timezone name;
58 // Unix "calendar" time in seconds
61 // Break down of equivalent GMT time
64 // offset of local time relative to GMT
70 // modified Julian date
73 // side real time at prime meridian
76 // local sidereal time
79 // the difference between the precise / expensive sidereal time
80 // algorithm result and the quick course result. course_gst +
81 // gst_diff has pretty good accuracy over the span of a couple hours
86 SGTime( const string& root );
89 // Initialize the time related variables
90 void init( double lon, double lat, const string& root );
92 // Update the time related variables
93 void update( double lon, double lat, long int warp = 0 );
95 // Given lon/lat, update timezone information and local_offset
96 void updateLocal( double lon, double lat, const string& root );
98 inline time_t get_cur_time() const { return cur_time; };
99 inline char* get_zonename() const { return zonename; }
100 inline struct tm* getGmt()const { return gmt; };
101 inline double getJD() const { return jd; };
102 inline double getMjd() const { return mjd; };
103 inline double getLst() const { return lst; };
104 inline double getGst() const { return gst; };
108 // Some useful utility functions that don't make sense to be part of
111 // Return unix time in seconds for the given data (relative to GMT)
112 time_t sgTimeGetGMT(int year, int month, int day,
113 int hour, int minute, int second);
115 // this is just a wrapper
116 inline time_t sgTimeGetGMT(struct tm* the_time) {
117 // printf("Using: %24s as input\n", asctime(the_time));
118 return sgTimeGetGMT(the_time->tm_year,
126 // given a date in months, mn, days, dy, years, yr, return the
127 // modified Julian date (number of days elapsed since 1900 jan 0.5),
128 // mjd. Adapted from Xephem.
129 double sgTimeCalcMJD(int mn, double dy, int yr);
131 // given an mjd, calculate greenwich mean sidereal time, gst
132 double sgTimeCalcGST( double mjd );
135 char* sgTimeFormatTime( const struct tm* p, char* buf );
138 #endif // _SG_TIME_HXX