OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
ossimplugins::CivilDateTime Class Reference

This class represents a date and time in the civil format. More...

#include <CivilDateTime.h>

Public Member Functions

 CivilDateTime ()
 Constructor. More...
 
 CivilDateTime (int year, int month, int day, int second, double decimal)
 Constructor with date and time initialisation. More...
 
 CivilDateTime (char *Utc)
 Constructor with date and time initialisation using an utc string. More...
 
 CivilDateTime (const char *Utc)
 
 ~CivilDateTime ()
 Destructor. More...
 
 CivilDateTime (const CivilDateTime &rhs)
 Copy constructor. More...
 
CivilDateTimeoperator= (const CivilDateTime &rhs)
 Affectation operator. More...
 
int AsJulianDate (JulianDate *julianDate)
 This function converts the current CivilDateTime into Julian Date. More...
 
int AsJSDDateTime (JSDDateTime *JSDdate)
 This function converts the current CivilDateTime into JSDDateTime. More...
 
int AsGMSTDateTime (GMSTDateTime *GMSTdate)
 This function converts the current CivilDateTime into GMSTDateTime. More...
 
int get_year ()
 
int get_month ()
 
int get_day ()
 
int get_second ()
 
double get_decimal ()
 
void set_year (int year)
 
void set_month (int month)
 
void set_day (int day)
 
void set_second (int second)
 
void set_decimal (double decimal)
 
int SetUtcDateTime (char *Utc)
 This function initialize the date and the the time of the class using an utc string. More...
 
int SetUtcDateTime (const char *Utc)
 
 operator JulianDate ()
 
 operator JSDDateTime ()
 
 operator GMSTDateTime ()
 
std::ostream & print (std::ostream &out) const
 

Static Public Attributes

static const double JOURCIVIL_LENGTH = 86400.0
 

Protected Attributes

int _year
 
int _month
 
int _day
 
int _second
 Number of secondes since the beginning of the day. More...
 
double _decimal
 

Friends

std::ostream & operator<< (std::ostream &out, const CivilDateTime &obj)
 

Detailed Description

This class represents a date and time in the civil format.

Definition at line 30 of file CivilDateTime.h.

Constructor & Destructor Documentation

◆ CivilDateTime() [1/5]

ossimplugins::CivilDateTime::CivilDateTime ( )

Constructor.

Definition at line 29 of file CivilDateTime.cpp.

29  :
30  _year(0),
31  _month(0),
32  _day(0),
33  _second(0),
34  _decimal(0.0)
35 {
36 }
int _second
Number of secondes since the beginning of the day.

◆ CivilDateTime() [2/5]

ossimplugins::CivilDateTime::CivilDateTime ( int  year,
int  month,
int  day,
int  second,
double  decimal 
)

Constructor with date and time initialisation.

Definition at line 38 of file CivilDateTime.cpp.

38  :
39  _year(year),
40  _month(month),
41  _day(day),
42  _second(second),
43  _decimal(decimal)
44 {
45 }
int _second
Number of secondes since the beginning of the day.

◆ CivilDateTime() [3/5]

ossimplugins::CivilDateTime::CivilDateTime ( char *  Utc)

Constructor with date and time initialisation using an utc string.

Definition at line 47 of file CivilDateTime.cpp.

References SetUtcDateTime().

48 {
49  SetUtcDateTime(Utc);
50 }
int SetUtcDateTime(char *Utc)
This function initialize the date and the the time of the class using an utc string.

◆ CivilDateTime() [4/5]

ossimplugins::CivilDateTime::CivilDateTime ( const char *  Utc)

Definition at line 52 of file CivilDateTime.cpp.

References SetUtcDateTime().

53 {
54  SetUtcDateTime(Utc);
55 }
int SetUtcDateTime(char *Utc)
This function initialize the date and the the time of the class using an utc string.

◆ ~CivilDateTime()

ossimplugins::CivilDateTime::~CivilDateTime ( )

Destructor.

Definition at line 57 of file CivilDateTime.cpp.

58 {
59 }

◆ CivilDateTime() [5/5]

ossimplugins::CivilDateTime::CivilDateTime ( const CivilDateTime rhs)

Copy constructor.

Definition at line 61 of file CivilDateTime.cpp.

61  :
62  _year(rhs._year),
63  _month(rhs._month),
64  _day(rhs._day),
65  _second(rhs._second),
66  _decimal(rhs._decimal)
67 {
68 
69 }
int _second
Number of secondes since the beginning of the day.

Member Function Documentation

◆ AsGMSTDateTime()

int ossimplugins::CivilDateTime::AsGMSTDateTime ( GMSTDateTime GMSTdate)

This function converts the current CivilDateTime into GMSTDateTime.

Returns
0 if no error or an int greater than 0 indicating the error
Parameters
GMSTdate[out] The classe that receives the result of the conversion of the current CivilDateTime into GMSTDateTime

Definition at line 389 of file CivilDateTime.cpp.

References _day, _decimal, _month, _second, _year, ossimplugins::GMSTDateTime::AN1900, ossimplugins::GMSTDateTime::AN1950, ossimplugins::GMSTDateTime::AN2000, AsJulianDate(), ossimplugins::JulianDate::get_julianDate(), ossimplugins::GMSTDateTime::get_origine(), JOURCIVIL_LENGTH, ossimplugins::GMSTDateTime::set_tms(), and TWOPI.

Referenced by ossimplugins::GMSTDateTime::GMSTDateTime(), and ossimplugins::ossimRadarSatModel::InitPlatformPosition().

390 {
391  const double TWOPI = 6.28318530717958647693 ;
392  const double OMEGATERRE = 6.28318530717958647693 / 86164.09054 ;
393  int etat ;
394  JulianDate jourJulien;
395  double t=0.0;
396  double tsm0hTU=0.0;
397  double tsm;
398  CivilDateTime date0hTU(_year, _month, _day, 0, 0.0);
399 
400 
401  etat = date0hTU.AsJulianDate(&jourJulien );
402  if (etat == 0)
403  {
404  if (GMST->get_origine() == GMSTDateTime::AN1900)
405  {
406  t = (jourJulien.get_julianDate() - 2415020.0) / 36525.0 ;
407  tsm0hTU = 23925.836 + t * (8640184.542 + t * 0.0929) ;
408  tsm0hTU = tsm0hTU * TWOPI / JOURCIVIL_LENGTH ;
409  }
410  else if (GMST->get_origine() == GMSTDateTime::AN1950)
411  {
412  t = jourJulien.get_julianDate() - 2433281.5 ;
413  tsm0hTU = 1.72944494 + t * 6.3003880987 ;
414  }
415  else if (GMST->get_origine() == GMSTDateTime::AN2000)
416  {
417  t = (jourJulien.get_julianDate() - 2451545.0) / 36525.0 ;
418  tsm0hTU = 24110.54841 + t * (8640184.812866 + t * (0.093103 - t * 6.210e-6)) ;
419  tsm0hTU = tsm0hTU * TWOPI / JOURCIVIL_LENGTH ;
420  }
421  t = tsm0hTU + ((double)_second + _decimal) * OMEGATERRE ;
422  tsm = fmod (t, TWOPI) ;
423 
424  if (tsm < 0.0)
425  {
426  tsm = tsm + TWOPI ;
427  }
428  GMST->set_tms(tsm);
429  }
430 
431  return etat ;
432 }
static const double JOURCIVIL_LENGTH
int _second
Number of secondes since the beginning of the day.

◆ AsJSDDateTime()

int ossimplugins::CivilDateTime::AsJSDDateTime ( JSDDateTime JSDdate)

This function converts the current CivilDateTime into JSDDateTime.

Returns
0 if no error or an int greater than 0 indicating the error
Parameters
JSDdate[out] The classe that receives the result of the conversion of the current CivilDateTime into JSDDateTime

Definition at line 367 of file CivilDateTime.cpp.

References AsJulianDate(), ossimplugins::JulianDate::get_julianDate(), ossimplugins::JSDDateTime::get_second(), JOURCIVIL_LENGTH, ossimplugins::JSDDateTime::set_day0hTU(), ossimplugins::JSDDateTime::set_decimal(), and ossimplugins::JSDDateTime::set_second().

Referenced by ossimplugins::JSDDateTime::JSDDateTime().

368 {
369  int etat , k ;
370  JulianDate jourJulien;
371  double r ;
372 
373  etat = AsJulianDate(&jourJulien );
374  if (etat == 0)
375  {
376  k = (int)(jourJulien.get_julianDate() - 0.5) ;
377 
378  double day0hTU = (double)k + 0.5;
379  JSDdate->set_day0hTU(JulianDate(day0hTU));
380 
381  r = (jourJulien.get_julianDate() - day0hTU) * JOURCIVIL_LENGTH ;
382  JSDdate->set_second(floor (r)) ;
383  JSDdate->set_decimal(r - JSDdate->get_second()) ;
384  }
385 
386  return etat ;
387 }
int AsJulianDate(JulianDate *julianDate)
This function converts the current CivilDateTime into Julian Date.
static const double JOURCIVIL_LENGTH

◆ AsJulianDate()

int ossimplugins::CivilDateTime::AsJulianDate ( JulianDate julianDate)

This function converts the current CivilDateTime into Julian Date.

Returns
0 if no error or an int greater than 0 indicating the error
Parameters
julianDate[out] The classe that receives the result of the conversion of the current CivilDateTime into JulianDate

Definition at line 82 of file CivilDateTime.cpp.

References _day, _decimal, _month, _second, _year, JOURCIVIL_LENGTH, and ossimplugins::JulianDate::set_julianDate().

Referenced by AsGMSTDateTime(), AsJSDDateTime(), and ossimplugins::JulianDate::JulianDate().

83 {
84  int etat , test ;
85  int an , mois , i , j ;
86  double b , d ;
87 
88  if (_month > 2)
89  {
90  an = _year ;
91  mois = _month ;
92  }
93  else
94  {
95  an = _year - 1 ;
96  mois = _month + 12 ;
97  }
98 
99  test = _year * 10000 + _month * 100 + _day ;
100  if ((test > 15821004) && (test < 15821015))
101  etat = 1 ;
102  else
103  {
104  etat = 0 ;
105  d = (an < 0) ? 0.75 : 0.0 ;
106  if (test >= 15821015)
107  {
108  i = an / 100 ;
109  j = 2 - i + i/4 ;
110  b = (double)j + 1720994.5 ;
111  }
112  else
113  b = 1720994.5 ;
114 
115  i = (int) (365.25 * (double)an - d) ;
116  j = (int) (30.6001 * (double)(mois + 1)) ;
117  double jourJulien = (double)(i + j) + (double)_day
118  + ((double)_second + _decimal) / JOURCIVIL_LENGTH + b ;
119 
120  julianDate->set_julianDate(jourJulien);
121  }
122 
123  return etat;
124 }
static const double JOURCIVIL_LENGTH
int _second
Number of secondes since the beginning of the day.

◆ get_day()

int ossimplugins::CivilDateTime::get_day ( )
inline

◆ get_decimal()

double ossimplugins::CivilDateTime::get_decimal ( )
inline

◆ get_month()

int ossimplugins::CivilDateTime::get_month ( )
inline

◆ get_second()

int ossimplugins::CivilDateTime::get_second ( )
inline

◆ get_year()

int ossimplugins::CivilDateTime::get_year ( )
inline

◆ operator GMSTDateTime()

ossimplugins::CivilDateTime::operator GMSTDateTime ( )

Definition at line 449 of file CivilDateTime.cpp.

450 {
451  GMSTDateTime date;
452  AsGMSTDateTime(&date);
453  return date;
454 }
int AsGMSTDateTime(GMSTDateTime *GMSTdate)
This function converts the current CivilDateTime into GMSTDateTime.

◆ operator JSDDateTime()

ossimplugins::CivilDateTime::operator JSDDateTime ( )

Definition at line 442 of file CivilDateTime.cpp.

443 {
444  JSDDateTime date;
445  AsJSDDateTime(&date);
446  return date;
447 }
int AsJSDDateTime(JSDDateTime *JSDdate)
This function converts the current CivilDateTime into JSDDateTime.

◆ operator JulianDate()

ossimplugins::CivilDateTime::operator JulianDate ( )

Definition at line 435 of file CivilDateTime.cpp.

436 {
437  JulianDate date;
438  AsJulianDate(&date);
439  return date;
440 }
int AsJulianDate(JulianDate *julianDate)
This function converts the current CivilDateTime into Julian Date.

◆ operator=()

CivilDateTime & ossimplugins::CivilDateTime::operator= ( const CivilDateTime rhs)

Affectation operator.

Definition at line 71 of file CivilDateTime.cpp.

References _day, _decimal, _month, _second, and _year.

72 {
73  _year = rhs._year;
74  _month = rhs._month;
75  _day = rhs._day;
76  _second = rhs._second;
77  _decimal = rhs._decimal;
78 
79  return *this;
80 }
int _second
Number of secondes since the beginning of the day.

◆ print()

std::ostream & ossimplugins::CivilDateTime::print ( std::ostream &  out) const

Definition at line 456 of file CivilDateTime.cpp.

References _day, _decimal, _month, _second, and _year.

Referenced by ossimplugins::operator<<().

457 {
458  out << "CivilDateTime:"
459  << "\nyear: " << _year
460  << "\nmonth: " << _month
461  << "\nday: " << _day
462  << "\nsecond: " << _second
463  << "\ndecimal: " << _decimal
464  << std::endl;
465 
466  return out;
467 }
int _second
Number of secondes since the beginning of the day.

◆ set_day()

void ossimplugins::CivilDateTime::set_day ( int  day)
inline

◆ set_decimal()

void ossimplugins::CivilDateTime::set_decimal ( double  decimal)
inline

◆ set_month()

void ossimplugins::CivilDateTime::set_month ( int  month)
inline

◆ set_second()

void ossimplugins::CivilDateTime::set_second ( int  second)
inline

◆ set_year()

void ossimplugins::CivilDateTime::set_year ( int  year)
inline

◆ SetUtcDateTime() [1/2]

int ossimplugins::CivilDateTime::SetUtcDateTime ( char *  Utc)

This function initialize the date and the the time of the class using an utc string.

Parameters
UtcUtc string containing the date and time
Returns
0 if no error or an int gretter than 0 indiquating the error

Definition at line 126 of file CivilDateTime.cpp.

References _day, _decimal, _month, _second, and _year.

Referenced by CivilDateTime().

127 {
128  char str_an[5];
129  char str_day[3];
130  char str_month[4];
131  char str_hour[3];
132  char str_min[3];
133  char str_sec[3];
134  char str_micro[7];
135  int i;
136  double exposant;
137 
138  /*
139  * year extraction
140  */
141  for (i = 0; i < 4; i++)
142  {
143  str_an[i] = Utc[i+7];
144  }
145 
146  str_an[4] = '\0';
147  _year = atoi(str_an);
148  if ( (_year > 2050) || (_year < 1950) )
149  {
150  return 1;
151  }
152 
153  /*
154  * month extraction
155  */
156  for (i = 0; i < 3; i++)
157  {
158  str_month[i] = Utc[i+3];
159  }
160 
161  str_month[3] = '\0';
162  if (!strcmp(str_month, "JAN")) _month = 1;
163  else if (!strcmp(str_month, "FEV")) _month = 2;
164  else if (!strcmp(str_month, "MAR")) _month = 3;
165  else if (!strcmp(str_month, "APR")) _month = 4;
166  else if (!strcmp(str_month, "MAY")) _month = 5;
167  else if (!strcmp(str_month, "JUN")) _month = 6;
168  else if (!strcmp(str_month, "JUL")) _month = 7;
169  else if (!strcmp(str_month, "AUG")) _month = 8;
170  else if (!strcmp(str_month, "SEP")) _month = 9;
171  else if (!strcmp(str_month, "OCT")) _month = 10;
172  else if (!strcmp(str_month, "NOV")) _month = 11;
173  else if (!strcmp(str_month, "DEC")) _month = 12;
174  else
175  {
176  return 1;
177  }
178 
179  /*
180  * day extraction
181  */
182  for (i = 0; i < 2; i++)
183  {
184  str_day[i] = Utc[i];
185  }
186 
187  str_day[2] = '\0';
188  _day = atoi(str_day);
189  if ( (_day < 1) || (_day > 31) )
190  {
191  return 1;
192  }
193 
194  /*
195  * seconds extraction
196  */
197  for (i = 0; i < 2; i++)
198  {
199  str_hour[i] = Utc[i+12];
200  str_min[i] = Utc[i+15];
201  str_sec[i] = Utc[i+18];
202  }
203 
204  str_hour[2] = '\0';if ( (atoi(str_hour) < 0) || (atoi(str_hour) > 23) )
205  {
206  return 1;
207  }
208 
209  str_min[2] = '\0';if ( (atoi(str_min) < 0) || (atoi(str_hour) > 59) )
210  {
211  return 1;
212  }
213  str_sec[2] = '\0';if ( (atoi(str_sec) < 0) || (atoi(str_hour) > 59) )
214  {
215  return 1;
216  }
217  _second = 3600*atoi(str_hour) + 60*atoi(str_min) + atoi(str_sec);
218 
219  /*
220  * microseconds extraction
221  */
222  for (i = 0; i < 6; i++)
223  {
224  str_micro[i] = Utc[i+21];
225  }
226 
227  str_micro[6] = '\0';
228  i = 0;
229  exposant = 10e-6;
230  while ((unsigned int)i < strlen(str_micro) )
231  {
232  if (str_micro[i] == '0') exposant = exposant * 0.1;
233  i++;
234  }
235 
236  _decimal = exposant * (double) atoi(str_micro);
237  if ( (_decimal < 0) || (_decimal >= 1) )
238  {
239  return 1;
240  }
241 
242  return 0;
243 
244 }
int _second
Number of secondes since the beginning of the day.

◆ SetUtcDateTime() [2/2]

int ossimplugins::CivilDateTime::SetUtcDateTime ( const char *  Utc)

Definition at line 246 of file CivilDateTime.cpp.

References _day, _decimal, _month, _second, and _year.

247 {
248  char str_an[5];
249  char str_day[3];
250  char str_month[4];
251  char str_hour[3];
252  char str_min[3];
253  char str_sec[3];
254  char str_micro[7];
255  int i;
256  double exposant;
257 
258  /*
259  * year extraction
260  */
261  for (i = 0; i < 4; i++)
262  {
263  str_an[i] = Utc[i+7];
264  }
265 
266  str_an[4] = '\0';
267  _year = atoi(str_an);
268  if ( (_year > 2050) || (_year < 1950) )
269  {
270  return 1;
271  }
272 
273  /*
274  * month extraction
275  */
276  for (i = 0; i < 3; i++)
277  {
278  str_month[i] = Utc[i+3];
279  }
280 
281  str_month[3] = '\0';
282  if (!strcmp(str_month, "JAN")) _month = 1;
283  else if (!strcmp(str_month, "FEV")) _month = 2;
284  else if (!strcmp(str_month, "MAR")) _month = 3;
285  else if (!strcmp(str_month, "APR")) _month = 4;
286  else if (!strcmp(str_month, "MAY")) _month = 5;
287  else if (!strcmp(str_month, "JUN")) _month = 6;
288  else if (!strcmp(str_month, "JUL")) _month = 7;
289  else if (!strcmp(str_month, "AUG")) _month = 8;
290  else if (!strcmp(str_month, "SEP")) _month = 9;
291  else if (!strcmp(str_month, "OCT")) _month = 10;
292  else if (!strcmp(str_month, "NOV")) _month = 11;
293  else if (!strcmp(str_month, "DEC")) _month = 12;
294  else
295  {
296  return 1;
297  }
298 
299  /*
300  * day extraction
301  */
302  for (i = 0; i < 2; i++)
303  {
304  str_day[i] = Utc[i];
305  }
306 
307  str_day[2] = '\0';
308  _day = atoi(str_day);
309  if ( (_day < 1) || (_day > 31) )
310  {
311  return 1;
312  }
313 
314  /*
315  * seconds extraction
316  */
317  for (i = 0; i < 2; i++)
318  {
319  str_hour[i] = Utc[i+12];
320  str_min[i] = Utc[i+15];
321  str_sec[i] = Utc[i+18];
322  }
323 
324  str_hour[2] = '\0';if ( (atoi(str_hour) < 0) || (atoi(str_hour) > 23) )
325  {
326  return 1;
327  }
328 
329  str_min[2] = '\0';if ( (atoi(str_min) < 0) || (atoi(str_hour) > 59) )
330  {
331  return 1;
332  }
333  str_sec[2] = '\0';if ( (atoi(str_sec) < 0) || (atoi(str_hour) > 59) )
334  {
335  return 1;
336  }
337  _second = 3600*atoi(str_hour) + 60*atoi(str_min) + atoi(str_sec);
338 
339  /*
340  * microseconds extraction
341  */
342  for (i = 0; i < 6; i++)
343  {
344  str_micro[i] = Utc[i+21];
345  }
346 
347  str_micro[6] = '\0';
348  i = 0;
349  exposant = 10e-6;
350  while ((unsigned int)i < strlen(str_micro) )
351  {
352  if (str_micro[i] == '0') exposant = exposant * 0.1;
353  i++;
354  }
355 
356  _decimal = exposant * (double) atoi(str_micro);
357  if ( (_decimal < 0) || (_decimal >= 1) )
358  {
359  return 1;
360  }
361 
362  return 0;
363 
364 }
int _second
Number of secondes since the beginning of the day.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const CivilDateTime obj 
)
friend

Definition at line 469 of file CivilDateTime.cpp.

470 {
471  return obj.print(out);
472 }

Member Data Documentation

◆ _day

int ossimplugins::CivilDateTime::_day
protected

Definition at line 172 of file CivilDateTime.h.

Referenced by AsGMSTDateTime(), AsJulianDate(), operator=(), print(), and SetUtcDateTime().

◆ _decimal

double ossimplugins::CivilDateTime::_decimal
protected

Definition at line 180 of file CivilDateTime.h.

Referenced by AsGMSTDateTime(), AsJulianDate(), operator=(), print(), and SetUtcDateTime().

◆ _month

int ossimplugins::CivilDateTime::_month
protected

Definition at line 168 of file CivilDateTime.h.

Referenced by AsGMSTDateTime(), AsJulianDate(), operator=(), print(), and SetUtcDateTime().

◆ _second

int ossimplugins::CivilDateTime::_second
protected

Number of secondes since the beginning of the day.

Definition at line 176 of file CivilDateTime.h.

Referenced by AsGMSTDateTime(), AsJulianDate(), operator=(), print(), and SetUtcDateTime().

◆ _year

int ossimplugins::CivilDateTime::_year
protected

Definition at line 164 of file CivilDateTime.h.

Referenced by AsGMSTDateTime(), AsJulianDate(), operator=(), print(), and SetUtcDateTime().

◆ JOURCIVIL_LENGTH

const double ossimplugins::CivilDateTime::JOURCIVIL_LENGTH = 86400.0
static

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