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 library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the
19 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 // Boston, MA 02111-1307, USA.
30 # error This library requires C++
38 #include <simgear/compiler.h>
40 #ifdef FG_HAVE_STD_INCLUDES
49 // Define a structure containing time parameters
53 // tzContainer stores all the current Timezone control points/
54 TimezoneContainer* tzContainer;
56 // Points to the current local timezone name;
59 // Unix "calendar" time in seconds
62 // Break down of equivalent GMT time
65 // offset of local time relative to GMT
71 // modified Julian date
74 // side real time at prime meridian
77 // local sidereal time
80 // the difference between the precise / expensive sidereal time
81 // algorithm result and the quick course result. course_gst +
82 // gst_diff has pretty good accuracy over the span of a couple hours
87 SGTime( double lon, double lat, const string& root );
88 SGTime( const string& root );
91 // Update the time related variables
92 void update( double lon, double lat, long int warp = 0 );
94 // Given lon/lat, update timezone information and local_offset
95 void updateLocal( double lon, double lat, const string& root );
97 inline time_t get_cur_time() const { return cur_time; };
98 inline char* get_zonename() const { return zonename; }
99 inline struct tm* getGmt()const { return gmt; };
100 inline double getJD() const { return jd; };
101 inline double getMjd() const { return mjd; };
102 inline double getLst() const { return lst; };
103 inline double getGst() const { return gst; };
107 // Some useful utility functions that don't make sense to be part of
110 // Return unix time in seconds for the given data (relative to GMT)
111 time_t sgTimeGetGMT(int year, int month, int day,
112 int hour, int minute, int second);
114 // this is just a wrapper
115 inline time_t sgTimeGetGMT(struct tm* the_time) {
116 // printf("Using: %24s as input\n", asctime(the_time));
117 return sgTimeGetGMT(the_time->tm_year,
125 // given a date in months, mn, days, dy, years, yr, return the
126 // modified Julian date (number of days elapsed since 1900 jan 0.5),
127 // mjd. Adapted from Xephem.
128 double sgTimeCalcMJD(int mn, double dy, int yr);
130 // given an mjd, calculate greenwich mean sidereal time, gst
131 double sgTimeCalcGST( double mjd );
134 char* sgTimeFormatTime( const struct tm* p, char* buf );
137 #endif // _SG_TIME_HXX