00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _SG_TIME_HXX
00028 #define _SG_TIME_HXX
00029
00030
00031 #ifndef __cplusplus
00032 # error This library requires C++
00033 #endif
00034
00035
00036 #include <simgear/compiler.h>
00037
00038 #include <ctime>
00039
00040 #include <simgear/timing/timezone.h>
00041
00042
00063 class SGTime {
00064
00065 private:
00066
00067 SGTimeZoneContainer* tzContainer;
00068
00069
00070 std::string zonename;
00071
00072
00073 time_t cur_time;
00074
00075
00076 struct tm m_gmt;
00077
00078
00079 time_t local_offset;
00080
00081
00082 double jd;
00083
00084
00085 double mjd;
00086
00087
00088 double gst;
00089
00090
00091 double lst;
00092
00093
00094
00095
00096 double gst_diff;
00097
00099 void init( double lon_rad, double lat_rad, const std::string& root,
00100 time_t init_time );
00101
00102 public:
00103
00105 SGTime();
00106
00123 SGTime( double lon_rad, double lat_rad, const std::string& root,
00124 time_t init_time );
00125
00130 SGTime( const std::string& root );
00131
00133 ~SGTime();
00134
00148 void update( double lon_rad, double lat_rad, time_t ct, long int warp );
00149
00160 void updateLocal( double lon_rad, double lat_rad, const std::string& root );
00161
00163 inline time_t get_cur_time() const { return cur_time; };
00164
00166 inline const char * get_zonename() const { return zonename.c_str(); }
00167
00169 inline struct tm* getGmt()const { return (struct tm *)&m_gmt; };
00170
00172 inline double getJD() const { return jd; };
00173
00175 inline double getMjd() const { return mjd; };
00176
00178 inline double getLst() const { return lst; };
00179
00181 inline double getGst() const { return gst; };
00182
00184 inline time_t get_local_offset() const { return local_offset; };
00185 };
00186
00187
00188
00189
00190
00202 time_t sgTimeGetGMT(int year, int month, int day,
00203 int hour, int minute, int second);
00204
00212 inline time_t sgTimeGetGMT(struct tm* the_time) {
00213
00214 return sgTimeGetGMT(the_time->tm_year,
00215 the_time->tm_mon,
00216 the_time->tm_mday,
00217 the_time->tm_hour,
00218 the_time->tm_min,
00219 the_time->tm_sec);
00220 }
00221
00231 double sgTimeCalcMJD(int mn, double dy, int yr);
00232
00242 double sgTimeCurrentMJD( time_t ct , long int warp );
00243
00249 double sgTimeCalcGST( double mjd );
00250
00258 char* sgTimeFormatTime( const struct tm* p, char* buf );
00259
00260
00261 #endif // _SG_TIME_HXX