Date Class Reference

#include <orsa_units.h>

List of all members.

Public Member Functions

 Date ()
 Date (const Date &)
 Date (const UniverseTypeAwareTime &)
void SetGregor (int y, int m, double d, TimeScale ts=default_Date_timescale)
 fractionary day, relative to 00:00
void SetGregor (int y, int m, int d, int H, int M, int S, int ms, TimeScale ts=default_Date_timescale)
void GetGregor (int &y, int &m, int &d, TimeScale ts=default_Date_timescale) const
double GetDayFraction (TimeScale ts=default_Date_timescale) const
unsigned int GetDayFraction_unsigned_int (TimeScale ts=default_Date_timescale) const
void SetJulian (double, TimeScale ts=default_Date_timescale)
void GetJulian (double &, TimeScale ts=default_Date_timescale) const
double GetJulian (TimeScale ts=default_Date_timescale) const
double Time () const
double GetTime () const
void SetTime (const double)
Dateoperator+= (const UniverseTypeAwareTimeStep &)
Dateoperator-= (const UniverseTypeAwareTimeStep &)
bool operator== (const Date &) const
bool operator!= (const Date &) const
bool operator< (const Date &) const
bool operator> (const Date &) const
void SetNow ()
void SetToday ()
void SetJ2000 ()
TimeStep GetTimeStep () const
 returns a TimeStep as big as the Date

Static Public Member Functions

static double delta_seconds (int y, int m, int d, const TimeScale from, const TimeScale to=default_Date_timescale)
 delta_seconds = to - from ('to' minus 'from')


Detailed Description

A note on Gregorian and Julian calendars: since its introduction in 1582, the Gregorian calendar has been adopted in different years from different countries, so the date obtained from the Date class can be different from the real 'old' one which used the Julian date, and usually the difference is of a few days.

In particular, ORSA applies the Gregorian calendar in any epoch, i.e. even before 1582. This appears to be the simplest solution, at least for the moment.

For more info, check out i.e. http://www.dome-igm.com/convers.htm

Definition at line 366 of file orsa_units.h.


Constructor & Destructor Documentation

Date  ) 
 

Definition at line 646 of file orsa_units.cc.

00646 : sdn(0), df(0) { }

Date const Date  ) 
 

Definition at line 650 of file orsa_units.cc.

00650 : sdn(d.sdn), df(d.df) { }

Date const UniverseTypeAwareTime  ) 
 

Definition at line 648 of file orsa_units.cc.

00648 : sdn(t.GetDate().sdn), df(t.GetDate().df) { }


Member Function Documentation

double delta_seconds int  y,
int  m,
int  d,
const TimeScale  from,
const TimeScale  to = default_Date_timescale
[static]
 

delta_seconds = to - from ('to' minus 'from')

Definition at line 499 of file orsa_units.cc.

References Date::delta_seconds(), orsa::ET_minus_UT_table, orsa::ET_minus_UT_table_final_element, orsa::GPS, orsa::TAI, orsa::TAI_minus_UTC_table, orsa::TAI_minus_UTC_table_final_element, orsa::TDT, orsa::UT1, and orsa::UTC.

Referenced by Date::delta_seconds(), Date::GetDayFraction_unsigned_int(), Date::GetGregor(), Date::GetJulian(), Date::SetGregor(), and Date::SetJulian().

00499                                                                                           {
00500     
00501     double delta_seconds=0.0;
00502     
00503     if (to==from) return delta_seconds;
00504     
00505     int j = 0;
00506     
00507     // convert from 'from' to TDT
00508     switch (from) {
00509       
00510     case TDT: 
00511       delta_seconds=0.0;
00512       break;
00513       
00514     case TAI:
00515       delta_seconds=32.184;
00516       break;
00517       
00518     case UTC:
00519       delta_seconds = 32.184;
00520       if (y>=TAI_minus_UTC_table[0].year) {
00521         j=0;
00522         TAI_minus_UTC_element candidate = TAI_minus_UTC_table[0];
00523         while (TAI_minus_UTC_table[j] != TAI_minus_UTC_table_final_element) {
00524           
00525           if (TAI_minus_UTC_table[j].year   <=y) {
00526             if (TAI_minus_UTC_table[j].month<=m) {
00527               if (TAI_minus_UTC_table[j].day<=d) {
00528                 if ( ( (TAI_minus_UTC_table[j].year >  candidate.year) ) ||
00529                      ( (TAI_minus_UTC_table[j].year == candidate.year) && (TAI_minus_UTC_table[j].month >  candidate.month) ) ||
00530                      ( (TAI_minus_UTC_table[j].year == candidate.year) && (TAI_minus_UTC_table[j].month == candidate.month) && (TAI_minus_UTC_table[j].day > candidate.day) ) ) { 
00531                   candidate = TAI_minus_UTC_table[j];
00532                 }               
00533               }
00534             }
00535           }
00536           
00537           j++;
00538         }
00539         
00540         delta_seconds += candidate.TAI_minus_UTC;
00541       }
00542       break;
00543       
00544     case UT1:
00545       delta_seconds = 0.0;
00546       if (y>=ET_minus_UT_table[0].year) {
00547         j=0;
00548         ET_minus_UT_element candidate=ET_minus_UT_table[0];
00549         while (ET_minus_UT_table[j] != ET_minus_UT_table_final_element) {
00550           
00551           if (ET_minus_UT_table[j].year   <=y) {
00552             if (ET_minus_UT_table[j].month<=m) {
00553               if (ET_minus_UT_table[j].day<=d) {
00554                 
00555                 if ( ( (ET_minus_UT_table[j].year >  candidate.year) ) ||
00556                      ( (ET_minus_UT_table[j].year == candidate.year) && (ET_minus_UT_table[j].month >  candidate.month) ) ||
00557                      ( (ET_minus_UT_table[j].year == candidate.year) && (ET_minus_UT_table[j].month == candidate.month) && (ET_minus_UT_table[j].day > candidate.day) ) ) {
00558                   candidate = ET_minus_UT_table[j];
00559                 }
00560               }
00561             }
00562           }
00563           
00564           j++;
00565         }
00566         delta_seconds += candidate.ET_minus_UT;
00567       }
00568       break;
00569       
00570     case GPS:
00571       delta_seconds = 32.184 + 19.0;
00572       break;
00573     }
00574     
00575     // convert from TDT to 'to'
00576     switch (to) {
00577       
00578     case TDT:
00579       break;
00580       
00581     case TAI: 
00582       delta_seconds -= 32.184; 
00583       break;
00584       
00585     case UTC: 
00586       delta_seconds -= 32.184;
00587       if (y>=TAI_minus_UTC_table[0].year) {
00588         j=0;
00589         TAI_minus_UTC_element candidate = TAI_minus_UTC_table[0];
00590         while (TAI_minus_UTC_table[j] != TAI_minus_UTC_table_final_element) {
00591           
00592           if (TAI_minus_UTC_table[j].year   <=y) {
00593             if (TAI_minus_UTC_table[j].month<=m) {
00594               if (TAI_minus_UTC_table[j].day<=d) {
00595                 if ( ( (TAI_minus_UTC_table[j].year >  candidate.year) ) ||
00596                      ( (TAI_minus_UTC_table[j].year == candidate.year) && (TAI_minus_UTC_table[j].month >  candidate.month) ) ||
00597                      ( (TAI_minus_UTC_table[j].year == candidate.year) && (TAI_minus_UTC_table[j].month == candidate.month) && (TAI_minus_UTC_table[j].day > candidate.day) ) ) { 
00598                   candidate = TAI_minus_UTC_table[j];
00599                 }
00600               }
00601             }
00602           }
00603           
00604           j++;
00605         }
00606         
00607         delta_seconds -= candidate.TAI_minus_UTC;
00608       }  
00609       break;
00610       
00611     case UT1:
00612       if (y>=ET_minus_UT_table[0].year) {
00613         j=0;
00614         ET_minus_UT_element candidate=ET_minus_UT_table[0];
00615         while (ET_minus_UT_table[j] != ET_minus_UT_table_final_element) {
00616           
00617           if (ET_minus_UT_table[j].year   <=y) {
00618             if (ET_minus_UT_table[j].month<=m) {
00619               if (ET_minus_UT_table[j].day<=d) {
00620                 if ( ( (ET_minus_UT_table[j].year >  candidate.year) ) ||
00621                      ( (ET_minus_UT_table[j].year == candidate.year) && (ET_minus_UT_table[j].month >  candidate.month) ) ||
00622                      ( (ET_minus_UT_table[j].year == candidate.year) && (ET_minus_UT_table[j].month == candidate.month) && (ET_minus_UT_table[j].day > candidate.day) ) ) {
00623                   candidate = ET_minus_UT_table[j];
00624                 }
00625               }
00626             }
00627           }
00628           
00629           j++;
00630         }
00631         
00632         delta_seconds -= candidate.ET_minus_UT;
00633       }
00634       break;
00635       
00636     case GPS: 
00637       delta_seconds -= (32.184 + 19.0);
00638       break;
00639     }
00640     
00641     // cerr << "delta_seconds: from " << TimeScaleLabel(from) << " to " << TimeScaleLabel(to) << " = " << delta_seconds << endl;
00642     
00643     return (delta_seconds);
00644   }

Here is the call graph for this function:

double GetDayFraction TimeScale  ts = default_Date_timescale  )  const
 

Definition at line 750 of file orsa_units.cc.

References Date::GetDayFraction_unsigned_int().

Referenced by orsa::gmst(), and Evolution::Integrate().

00750                                                 {
00751     return (GetDayFraction_unsigned_int(ts)*1.0)/(TimeStep::max_day_fraction());
00752   }

Here is the call graph for this function:

unsigned int GetDayFraction_unsigned_int TimeScale  ts = default_Date_timescale  )  const
 

Definition at line 754 of file orsa_units.cc.

References Date::delta_seconds().

Referenced by Date::GetDayFraction().

00754                                                                    {
00755     int y,m,d;
00756     SdnToGregorian(sdn, &y, &m, &d);
00757     const double ds = delta_seconds(y,m,d,ts);
00758     const int delta_df = - (int)(ds*(TimeStep::max_day_fraction() / 86400)); // negative!
00759     unsigned int local_df = 0;
00760     if (delta_df < 0) {
00761       if (abs(delta_df) > df) {
00762         local_df = TimeStep::max_day_fraction() + df - abs(delta_df);
00763       } else {
00764         local_df = df + delta_df;
00765       }
00766     } else {
00767       local_df = df + delta_df;
00768     }
00769     local_df %= TimeStep::max_day_fraction();
00770     return (local_df);
00771   }

Here is the call graph for this function:

void GetGregor int &  y,
int &  m,
int &  d,
TimeScale  ts = default_Date_timescale
const
 

Definition at line 734 of file orsa_units.cc.

References Date::delta_seconds().

Referenced by Evolution::Integrate().

00734                                                                  {
00735     SdnToGregorian(sdn, &y, &m, &d);
00736     const double ds = delta_seconds(y,m,d,ts);
00737     const int delta_df = - (int)(ds*(TimeStep::max_day_fraction() / 86400)); // negative!
00738     if (delta_df < 0) {
00739       if (abs(delta_df) > df) {
00740         SdnToGregorian(sdn-1, &y, &m, &d);
00741       }
00742     } else {
00743       const unsigned int local_df = df + delta_df;
00744       if (local_df >= TimeStep::max_day_fraction()) {
00745         SdnToGregorian(sdn+1, &y, &m, &d);
00746       }
00747     }
00748   }

Here is the call graph for this function:

double GetJulian TimeScale  ts = default_Date_timescale  )  const
 

Definition at line 860 of file orsa_units.cc.

References Date::GetJulian().

00860                                            {
00861     double jd;
00862     GetJulian(jd,ts);
00863     return jd;
00864   }

Here is the call graph for this function:

void GetJulian double &  ,
TimeScale  ts = default_Date_timescale
const
 

Definition at line 854 of file orsa_units.cc.

References Date::delta_seconds().

Referenced by orsa::alpha_delta_meridian(), orsa::alpha_delta_meridian_moon(), orsa::BuildObservationTriplets(), Date::GetJulian(), Date::GetTime(), orsa::gmst(), orsa::obleq(), Observation::operator<(), TLEFile::Read(), and Date::Time().

00854                                                       {
00855     int y,m,d;
00856     SdnToGregorian(sdn, &y, &m, &d);
00857     jd = sdn + ((df*1.0)/ TimeStep::max_day_fraction()) - 0.5 - (1.0/86400.0)*delta_seconds(y,m,d,ts);
00858   }

Here is the call graph for this function:

double GetTime  )  const
 

Definition at line 777 of file orsa_units.cc.

References orsa::DAY, orsa::FromUnits(), and Date::GetJulian().

Referenced by UniverseTypeAwareTime::GetTime(), and UniverseTypeAwareTime::SetDate().

00777                              {
00778     return (FromUnits(GetJulian(),DAY));
00779   }

Here is the call graph for this function:

TimeStep GetTimeStep  )  const [inline]
 

returns a TimeStep as big as the Date

Definition at line 407 of file orsa_units.h.

Referenced by UniverseTypeAwareTime::operator-(), UniverseTypeAwareTime::operator<(), Date::operator<(), UniverseTypeAwareTime::operator<=(), UniverseTypeAwareTime::operator>(), Date::operator>(), and UniverseTypeAwareTime::operator>=().

00407                                  {
00408       return TimeStep(sdn,df,+1);
00409     }

bool operator!= const Date  )  const
 

Definition at line 819 of file orsa_units.cc.

00819                                               {
00820     return (!((*this)==d));
00821   }

Date & operator+= const UniverseTypeAwareTimeStep  ) 
 

Definition at line 785 of file orsa_units.cc.

00785                                                                 {
00786     
00787     sdn += ts.sign() * ts.days();
00788     
00789     if (ts.sign() == -1) {
00790       if (ts.day_fraction() > df) {
00791         --sdn;
00792         df = TimeStep::max_day_fraction() + df - ts.day_fraction();
00793       } else {
00794         df -= ts.day_fraction();
00795       }
00796     } else {
00797       df += ts.day_fraction();
00798     }
00799     
00800     while (df >= TimeStep::max_day_fraction()) {
00801       ++sdn;
00802       df -= TimeStep::max_day_fraction();
00803     }
00804     
00805     return * this;
00806   }

Date & operator-= const UniverseTypeAwareTimeStep  ) 
 

Definition at line 808 of file orsa_units.cc.

00808                                                                 {
00809     * this += - ts;
00810     return * this;
00811   }

bool operator< const Date  )  const
 

Definition at line 823 of file orsa_units.cc.

References Date::GetTimeStep().

00823                                              {
00824     return (GetTimeStep() < d.GetTimeStep());
00825   }

Here is the call graph for this function:

bool operator== const Date  )  const
 

Definition at line 813 of file orsa_units.cc.

00813                                               {
00814     if (sdn != d.sdn) return false;
00815     if (df != d.df) return false;
00816     return true;
00817   }

bool operator> const Date  )  const
 

Definition at line 827 of file orsa_units.cc.

References Date::GetTimeStep().

00827                                              {
00828     return (GetTimeStep() > d.GetTimeStep());
00829   }

Here is the call graph for this function:

void SetGregor int  y,
int  m,
int  d,
int  H,
int  M,
int  S,
int  ms,
TimeScale  ts = default_Date_timescale
 

Definition at line 676 of file orsa_units.cc.

References Date::delta_seconds(), and orsa::M.

00676                                                                                      {
00677     
00678     ms += (int)(1000.0 * delta_seconds(y,m,d,ts));
00679     
00680     // checks...
00681     while (ms >= 1000) {
00682       S  += 1;
00683       ms -= 1000;
00684     }
00685     while (S >= 60) {
00686       M += 1;
00687       S -= 60;
00688     }
00689     while (M >= 60) {
00690       H += 1;
00691       M -= 60;
00692     }
00693     while (H >= 24) {
00694       d += 1;
00695       H -= 24;
00696     }
00697     
00698     // more...
00699     while (ms < 0) {
00700       S  -= 1;
00701       ms += 60;
00702     }
00703     while (S < 0) {
00704       M -= 1;
00705       S += 60;
00706     }
00707     while (M < 0) {
00708       H -= 1;
00709       M += 60;
00710     }
00711     while (H < 0) {
00712       d -= 1;
00713       H += 24;
00714     }
00715     
00716     sdn = GregorianToSdn(y,m,d);
00717     df  = ( ( (H * 60 + M) * 60 + S) * 1000 + ms) * (TimeStep::max_day_fraction() / 86400000);
00718   }

Here is the call graph for this function:

void SetGregor int  y,
int  m,
double  d,
TimeScale  ts = default_Date_timescale
 

fractionary day, relative to 00:00

Definition at line 653 of file orsa_units.cc.

References orsa::M.

Referenced by TLEFile::Read(), JPLDastcomCometFile::Read(), RWOFile::Read(), MPCObsFile::Read(), MPCCometFile::Read(), MPCOrbFile::Read(), AstorbFile::Read(), and Date::SetNow().

00653                                                              {
00654     
00655     int id = (int)(floor(d));
00656     d -= id;
00657     //
00658     d *= 24;
00659     int H = (int)(floor(d));
00660     d -= H;
00661     //
00662     d *= 60;
00663     int M = (int)(floor(d));
00664     d -= M;
00665     //
00666     d *= 60;
00667     int S = (int)(floor(d));
00668     d -= S;
00669     //
00670     d *= 1000;
00671     int ms = (int)(floor(d));
00672     
00673     SetGregor(y,m,id,H,M,S,ms,ts);
00674   }

void SetJ2000  ) 
 

Definition at line 887 of file orsa_units.cc.

References Date::SetJulian(), and orsa::TT.

Referenced by orsa::alpha_delta_meridian(), orsa::alpha_delta_meridian_moon(), and orsa::obleq_J2000().

00887                       {
00888     SetJulian(2451545.0,TT); /* IAU definition: [2000 Jan 1d 12h TDT]
00889                                 http://en.wikipedia.org/wiki/Terrestrial_Time 
00890                                 http://en.wikipedia.org/wiki/Month 
00891                                 http://aa.usno.navy.mil/software/novas/novas_c/novasc_info.html
00892                                 http://nanotitan.com/software/api/suite/diamond/nT/quantity/constant/TIME_INSTANT.html#J2000
00893                              */
00894   }

Here is the call graph for this function:

void SetJulian double  ,
TimeScale  ts = default_Date_timescale
 

Definition at line 831 of file orsa_units.cc.

References Date::delta_seconds().

Referenced by TLEFile::Read(), NEODYSCAT::Read(), JPLDastcomCometFile::Read(), JPLDastcomUnnumFile::Read(), JPLDastcomNumFile::Read(), AstDySMatrixFile::Read(), Date::SetJ2000(), UniverseTypeAwareTime::SetTime(), and Date::SetTime().

00831                                               {
00832     sdn = (unsigned int)(floor(jd));
00833     double frac = jd - floor(jd) + 0.5;
00834     if (frac >= 1.0) {
00835       ++sdn;
00836       frac = fmod(frac,1.0);
00837     }
00838     //
00839     {
00840       int y,m,d;
00841       SdnToGregorian(sdn, &y, &m, &d);
00842       jd += (1.0/86400.0)*delta_seconds(y,m,d,ts);
00843     }
00844     sdn = (unsigned int)(floor(jd));
00845     frac = jd - floor(jd) + 0.5;
00846     if (frac >= 1.0) {
00847       ++sdn;
00848       frac = fmod(frac,1.0);
00849     }
00850     
00851     df = (unsigned int)rint(frac * TimeStep::max_day_fraction());
00852   }

Here is the call graph for this function:

void SetNow  ) 
 

Definition at line 866 of file orsa_units.cc.

References Date::SetGregor(), and orsa::UTC.

Referenced by Date::SetToday().

00866                     {
00867     const time_t tt_now = time(0);
00868     struct tm *tm_struct = gmtime(&tt_now);
00869     // this is accurate down to a second, microseconds are not used
00870     // if they were, the term is ...tm_sec+(tv.tv_usec*1.0e-6))...
00871     // SetGregor(1900+tm_struct->tm_year,1+tm_struct->tm_mon,tm_struct->tm_mday+((tm_struct->tm_sec)/86400.0+tm_struct->tm_min/1440.0+tm_struct->tm_hour/24.0),UTC);
00872     SetGregor(1900+tm_struct->tm_year,
00873               1+tm_struct->tm_mon,
00874               tm_struct->tm_mday,
00875               tm_struct->tm_hour,
00876               tm_struct->tm_min,
00877               tm_struct->tm_sec,
00878               0, // ms
00879               UTC);
00880   }

Here is the call graph for this function:

void SetTime const   double  ) 
 

Definition at line 781 of file orsa_units.cc.

References orsa::DAY, orsa::FromUnits(), and Date::SetJulian().

00781                                    {
00782     SetJulian(FromUnits(t,DAY,-1));
00783   }

Here is the call graph for this function:

void SetToday  ) 
 

Definition at line 882 of file orsa_units.cc.

References Date::SetNow().

00882                       {
00883     SetNow();
00884     df = 0; // reset day fraction
00885   }

Here is the call graph for this function:

double Time  )  const
 

Definition at line 773 of file orsa_units.cc.

References orsa::DAY, orsa::FromUnits(), and Date::GetJulian().

00773                           {
00774     return (FromUnits(GetJulian(),DAY));
00775   }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Tue Jan 11 15:29:52 2005 for liborsa by  doxygen 1.4.0