simgear  3.5.0 [next] git://gitorious.org/fg/simgear.git
SimGear - Simulator Construction Tools
SGTime Class Reference

#include <sg_time.hxx>

Public Member Functions

 SGTime ()
 
 SGTime (const SGGeod &location, const SGPath &root, time_t init_time)
 
 SGTime (const SGPath &root)
 
 ~SGTime ()
 
time_t get_cur_time () const
 
time_t get_local_offset () const
 
const char * get_zonename () const
 
struct tm * getGmt () const
 
double getGst () const
 
double getJD () const
 
double getLst () const
 
double getMjd () const
 
void update (const SGGeod &location, time_t ct, long int warp)
 
void update (double lon_rad, double lat_rad, time_t ct, long int warp) DEPRECATED
 
void updateLocal (const SGGeod &location, const std::string &root)
 

Private Member Functions

void init (const SGGeod &location, const SGPath &root, time_t init_time)
 

Private Attributes

time_t cur_time
 
double gst
 
double gst_diff
 
double jd
 
time_t local_offset
 
double lst
 
struct tm m_gmt
 
double mjd
 
std::string zonename
 

Related Functions

(Note that these are not member functions.)

double sgTimeCalcGST (double mjd)
 
double sgTimeCalcMJD (int mn, double dy, int yr)
 
double sgTimeCurrentMJD (time_t ct, long int warp)
 
char * sgTimeFormatTime (const struct tm *p, char *buf)
 
time_t sgTimeGetGMT (int year, int month, int day, int hour, int minute, int second)
 
time_t sgTimeGetGMT (struct tm *the_time)
 

Detailed Description

A class to calculate and manage a variety of time parameters. The SGTime class provides many real-world time values. It calculates current time in seconds, GMT time, local time zone, local offset in seconds from GMT, Julian date, and sidereal time. All of these operate with seconds as their granularity so this class is not intended for timing sub-second events. These values are intended as input to things like real world lighting calculations and real astronomical object placement.

To properly use the SGTime class there are a couple of things to be aware of. After creating an instance of the class, you will need to periodically (i.e. before every frame) call the update() method. Optionally, if you care about updating time zone information based on your latitude and longitude, you can call the updateLocal() method periodically as your position changes by significant amounts.

Definition at line 66 of file sg_time.hxx.

Constructor & Destructor Documentation

SGTime::SGTime ( )

Default constructor

Definition at line 117 of file sg_time.cxx.

SGTime::SGTime ( const SGGeod location,
const SGPath root,
time_t  init_time 
)

Create an instance based on a specified position and data file path. This creates an instance of the SGTime object. When calling the constructor you need to provide a root path pointing to your time zone definition tree. Optionally, you can call a form of the constructor that accepts your current longitude and latitude in radians.

If you don't know your position when you call the SGTime constructor, you can just use the first form (which assumes 0, 0).

Parameters
locationCurrent geodetic location
rootRoot path point to data file location (timezone, etc.)
init_timeProvide an initialization time, 0 means use current clock time

Definition at line 106 of file sg_time.cxx.

SGTime::SGTime ( const SGPath root)

Create an instance given a data file path.

Parameters
rootroot path point to data file location (timezone, etc.)

Definition at line 112 of file sg_time.cxx.

SGTime::~SGTime ( )

Destructor

Definition at line 122 of file sg_time.cxx.

Member Function Documentation

time_t SGTime::get_cur_time ( ) const
inline
Returns
current system/unix time in seconds

Definition at line 171 of file sg_time.hxx.

time_t SGTime::get_local_offset ( ) const
inline
Returns
offset in seconds to local timezone time

Definition at line 192 of file sg_time.hxx.

const char* SGTime::get_zonename ( ) const
inline
Returns
time zone name for your current position

Definition at line 174 of file sg_time.hxx.

struct tm* SGTime::getGmt ( ) const
inline
Returns
GMT in a "brokent down" tm structure

Definition at line 177 of file sg_time.hxx.

double SGTime::getGst ( ) const
inline
Returns
grenich side real time (lst when longitude == 0)

Definition at line 189 of file sg_time.hxx.

double SGTime::getJD ( ) const
inline
Returns
julian date

Definition at line 180 of file sg_time.hxx.

double SGTime::getLst ( ) const
inline
Returns
local side real time

Definition at line 186 of file sg_time.hxx.

double SGTime::getMjd ( ) const
inline
Returns
modified julian date

Definition at line 183 of file sg_time.hxx.

void SGTime::init ( const SGGeod location,
const SGPath root,
time_t  init_time 
)
private

init common constructor code

Definition at line 71 of file sg_time.cxx.

Referenced by SGTime().

void SGTime::update ( const SGGeod location,
time_t  ct,
long int  warp 
)

Update the time related variables. The update() method requires you to pass in your position and an optional time offset in seconds. The offset (or warp) allows you to offset "sim" time relative to "real" time. The update() method is designed to be called by the host application before every frame.

Parameters
locationCurrent geodetic location
ctSpecify a unix time, otherwise specify 0 to use current clock time
warpOptional time offset in seconds. This allows to advance or rewind "time".

Definition at line 181 of file sg_time.cxx.

Referenced by update().

void SGTime::update ( double  lon_rad,
double  lat_rad,
time_t  ct,
long int  warp 
)

Deprecated method. To be removed after the next release...

Definition at line 174 of file sg_time.cxx.

void SGTime::updateLocal ( const SGGeod location,
const std::string &  root 
)

Given lon/lat, update timezone information and local_offset The updateLocal() method is intended to be called less frequently - only when your position is likely to be changed enough that your timezone may have changed as well. In the FlightGear project we call updateLocal() every few minutes from our periodic event manager.

Parameters
locationCurrent geodetic location
rootBbase path containing time zone directory

Definition at line 234 of file sg_time.cxx.

Friends And Related Function Documentation

double sgTimeCalcGST ( double  mjd)
related

Given an mjd, calculate greenwich mean sidereal time, gst

Parameters
mjdmodified julian date
Returns
greenwich mean sidereal time (gst)

Definition at line 343 of file sg_time.cxx.

Referenced by sidereal_precise().

double sgTimeCalcMJD ( int  mn,
double  dy,
int  yr 
)
related

Given a date in our form, return the equivalent modified Julian date (number of days elapsed since 1900 jan 0.5), mjd. Adapted from Xephem.

Parameters
mnmonth
dyday
yryear
Returns
modified julian date

Definition at line 265 of file sg_time.cxx.

Referenced by sgTimeCurrentMJD().

double sgTimeCurrentMJD ( time_t  ct,
long int  warp 
)
related

Given an optional offset from current time calculate the current modified julian date.

Parameters
ctspecify a unix time, otherwise specify 0 to use current clock time
warpnumber of seconds to offset from current time (0 if no offset)
Returns
current modified Julian date (number of days elapsed since 1900 jan 0.5), mjd.

Definition at line 315 of file sg_time.cxx.

Referenced by update().

char * sgTimeFormatTime ( const struct tm *  p,
char *  buf 
)
related

Format time in a pretty form

Parameters
ptime specified in a tm struct
bufbuffer space to contain the result
Returns
pointer to character array containt the result

Definition at line 506 of file sg_time.cxx.

time_t sgTimeGetGMT ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second 
)
related

Return unix time in seconds for the given date (relative to GMT)

Parameters
yearcurrent GMT year
monthcurrent GMT month
daycurrent GMT day
hourcurrent GMT hour
minutecurrent minute
secondcurrent second
Returns
unix/system time in seconds

Definition at line 410 of file sg_time.cxx.

Referenced by sgTimeGetGMT(), sidereal_course(), and updateLocal().

time_t sgTimeGetGMT ( struct tm *  the_time)
related

this is just a wrapper for sgTimeGetGMT that allows an alternate form of input parameters.

Parameters
the_timethe current GMT time in the tm structure
Returns
unix/system time in seconds

Definition at line 220 of file sg_time.hxx.

Member Data Documentation

time_t SGTime::cur_time
private

Definition at line 74 of file sg_time.hxx.

Referenced by get_cur_time(), init(), update(), and updateLocal().

double SGTime::gst
private

Definition at line 89 of file sg_time.hxx.

Referenced by getGst(), and update().

double SGTime::gst_diff
private

Definition at line 97 of file sg_time.hxx.

Referenced by init(), and update().

double SGTime::jd
private

Definition at line 83 of file sg_time.hxx.

Referenced by getJD(), and update().

time_t SGTime::local_offset
private

Definition at line 80 of file sg_time.hxx.

Referenced by get_local_offset(), and updateLocal().

double SGTime::lst
private

Definition at line 92 of file sg_time.hxx.

Referenced by getLst(), and update().

struct tm SGTime::m_gmt
private

Definition at line 77 of file sg_time.hxx.

Referenced by getGmt(), and update().

double SGTime::mjd
private

Definition at line 86 of file sg_time.hxx.

Referenced by getMjd(), and update().

std::string SGTime::zonename
private

Definition at line 71 of file sg_time.hxx.

Referenced by init(), and updateLocal().


The documentation for this class was generated from the following files: