time_conversion.c
Go to the documentation of this file.
1 // TAKEN FROM https://svn.code.sf.net/p/gnsstk/code/trunk/src/time_conversion.c
2 
48 #include <sys/timeb.h>
49 #include <time.h>
50 #include <math.h> // for fmod()
51 #include "time_conversion.h"
52 #include "ISConstants.h"
53 
54 #define TIMECONV_JULIAN_DATE_START_OF_GPS_TIME (2444244.5) // [days]
55 #define TIMECONV_JULIAN_DATE_START_OF_PC_TIME (2440587.5) // [days]
56 #define TIMECONV_DAYS_IN_JAN 31
57 #define TIMECONV_DAYS_IN_MAR 31
58 #define TIMECONV_DAYS_IN_APR 30
59 #define TIMECONV_DAYS_IN_MAY 31
60 #define TIMECONV_DAYS_IN_JUN 30
61 #define TIMECONV_DAYS_IN_JUL 31
62 #define TIMECONV_DAYS_IN_AUG 31
63 #define TIMECONV_DAYS_IN_SEP 30
64 #define TIMECONV_DAYS_IN_OCT 31
65 #define TIMECONV_DAYS_IN_NOV 30
66 #define TIMECONV_DAYS_IN_DEC 31
67 
68 
69 // A static function to check if the utc input values are valid.
70 // \return 1 if valid, 0 otherwise.
71 static int TIMECONV_IsUTCTimeValid(
72  const unsigned short utc_year,
73  const unsigned char utc_month,
74  const unsigned char utc_day,
75  const unsigned char utc_hour,
76  const unsigned char utc_minute,
77  const float utc_seconds
78  );
79 
80 
82  const unsigned short utc_year,
83  const unsigned char utc_month,
84  const unsigned char utc_day,
85  const unsigned char utc_hour,
86  const unsigned char utc_minute,
87  const float utc_seconds
88  )
89 {
90  unsigned char daysInMonth;
91  int result;
92  if( utc_month == 0 || utc_month > 12 )
93  {
94  GNSS_ERROR_MSG( "if( utc_month == 0 || utc_month > 12 )" );
95  return 0;
96  }
97  result = TIMECONV_GetNumberOfDaysInMonth( utc_year, utc_month, &daysInMonth );
98  if( result == 0 )
99  {
100  GNSS_ERROR_MSG( "TIMECONV_GetNumberOfDaysInMonth returned 0." );
101  return 0;
102  }
103  if( utc_day == 0 || utc_day > daysInMonth )
104  {
105  GNSS_ERROR_MSG( "if( utc_day == 0 || utc_day > daysInMonth )" );
106  return 0;
107  }
108  if( utc_hour > 23 )
109  {
110  GNSS_ERROR_MSG( "if( utc_hour > 23 )" );
111  return 0;
112  }
113  if( utc_minute > 59 )
114  {
115  GNSS_ERROR_MSG( "if( utc_minute > 59 )" );
116  return 0;
117  }
118  if( utc_seconds > 60 )
119  {
120  GNSS_ERROR_MSG( "if( utc_seconds > 60 )" );
121  return 0;
122  }
123 
124  return 1;
125 }
126 
127 
129  unsigned short* utc_year,
130  unsigned char* utc_month,
131  unsigned char* utc_day,
132  unsigned char* utc_hour,
133  unsigned char* utc_minute,
134  float* utc_seconds,
135  unsigned char* utc_offset,
136  double* julian_date,
137  unsigned short* gps_week,
138  double* gps_tow
139  )
140 {
141  int result;
142 
143 #ifdef WIN32
144  struct _timeb timebuffer; // found in <sys/timeb.h>
145 #else
146  struct timeb timebuffer;
147 #endif
148  double timebuffer_time_in_days;
149  double timebuffer_time_in_seconds;
150  //char *timeline; // for debugging
151 
152 #ifdef WIN32
153  _ftime( &timebuffer );
154 #else
155  ftime( &timebuffer );
156 #endif
157 
158  //timeline = ctime( & ( timebuffer.time ) ); // for debugging
159  //printf( "%s\n", timeline ); // for debugging
160 
161  timebuffer_time_in_seconds = timebuffer.time + timebuffer.millitm / 1000.0; // [s] with ms resolution
162 
163  // timebuffer_time_in_seconds is the time in seconds since midnight (00:00:00), January 1, 1970,
164  // coordinated universal time (UTC). Julian date for (00:00:00), January 1, 1970 is: 2440587.5 [days]
165 
166  // convert timebuffer.time from seconds to days
167  timebuffer_time_in_days = timebuffer_time_in_seconds/SECONDS_IN_DAY; // days since julian date 2440587.5000000 [days]
168 
169  // convert to julian date
170  *julian_date = TIMECONV_JULIAN_DATE_START_OF_PC_TIME + timebuffer_time_in_days;
171 
172  result = TIMECONV_DetermineUTCOffset( *julian_date, utc_offset );
173  if( result == 0 )
174  {
175  GNSS_ERROR_MSG( "TIMECONV_DetermineUTCOffset returned 0." );
176  return 0;
177  }
178 
180  *julian_date,
181  *utc_offset,
182  gps_week,
183  gps_tow );
184  if( result == 0 )
185  {
186  GNSS_ERROR_MSG( "TIMECONV_GetGPSTimeFromJulianDate returned 0." );
187  return 0;
188  }
189 
191  *julian_date,
192  utc_year,
193  utc_month,
194  utc_day,
195  utc_hour,
196  utc_minute,
197  utc_seconds );
198  if( result == 0 )
199  {
200  GNSS_ERROR_MSG( "TIMECONV_GetUTCTimeFromJulianDate" );
201  return 0;
202  }
203 
204  return 1;
205 }
206 
207 
208 #ifdef WIN32
209 int TIMECONV_SetSystemTime(
210  const unsigned short utc_year,
211  const unsigned char utc_month,
212  const unsigned char utc_day,
213  const unsigned char utc_hour,
214  const unsigned char utc_minute,
215  const float utc_seconds
216  )
217 {
218  int result;
219  SYSTEMTIME t;
220  double julian_date = 0;
221  unsigned char day_of_week = 0;
222 
224  utc_year,
225  utc_month,
226  utc_day,
227  utc_hour,
228  utc_minute,
229  utc_seconds,
230  &julian_date
231  );
232  if( !result )
233  {
234  GNSS_ERROR_MSG( "TIMECONV_GetJulianDateFromUTCTime returned 0.");
235  return 0;
236  }
237 
238  result = TIMECONV_GetDayOfWeekFromJulianDate( julian_date, &day_of_week );
239  if( !result )
240  {
241  GNSS_ERROR_MSG( "TIMECONV_GetDayOfWeekFromJulianDate returned 0.");
242  return 0;
243  }
244 
245  t.wDayOfWeek = day_of_week;
246  t.wYear = utc_year;
247  t.wMonth = utc_month;
248  t.wDay = utc_day;
249  t.wHour = utc_hour;
250  t.wMinute = utc_minute;
251  t.wSecond = (WORD)(floor(utc_seconds));
252  t.wMilliseconds = (WORD)((utc_seconds - t.wSecond)*1000);
253 
254  // Set the PC system time.
255  result = SetSystemTime( &t );
256 
257  return result;
258 }
259 #endif
260 
261 
263  const double julian_date,
264  unsigned char *day_of_week
265  )
266 {
267  // "If the Julian date of noon is applied to the entire midnight-to-midnight civil
268  // day centered on that noon,[5] rounding Julian dates (fractional days) for the
269  // twelve hours before noon up while rounding those after noon down, then the remainder
270  // upon division by 7 represents the day of the week, with 0 representing Monday,
271  // 1 representing Tuesday, and so forth. Now at 17:48, Wednesday December 3 2008 (UTC)
272  // the nearest noon JDN is 2454804 yielding a remainder of 2." (http://en.wikipedia.org/wiki/Julian_day, 2008-12-03)
273  int dow = 0;
274  int jd = 0;
275 
276  if( julian_date - floor(julian_date) > 0.5 )
277  {
278  jd = (int)floor(julian_date+0.5);
279  }
280  else
281  {
282  jd = (int)floor(julian_date);
283  }
284  dow = jd%7; // 0 is monday, 1 is tuesday, etc
285 
286  switch( dow )
287  {
288  case 0: *day_of_week = 1; break;
289  case 1: *day_of_week = 2; break;
290  case 2: *day_of_week = 3; break;
291  case 3: *day_of_week = 4; break;
292  case 4: *day_of_week = 5; break;
293  case 5: *day_of_week = 6; break;
294  case 6: *day_of_week = 0; break;
295  default: return 0; break;
296  }
297 
298  return 1;
299 }
300 
301 
303  const unsigned short gps_week,
304  const double gps_tow,
305  const unsigned char utc_offset,
306  double* julian_date
307  )
308 {
309  if( gps_tow < 0.0 || gps_tow > 604800.0 )
310  {
311  GNSS_ERROR_MSG( "if( gps_tow < 0.0 || gps_tow > 604800.0 )" );
312  return 0;
313  }
314 
315  // GPS time is ahead of UTC time and Julian time by the UTC offset
316  *julian_date = ((double)gps_week + (gps_tow-(double)utc_offset)/604800.0)*7.0 + TIMECONV_JULIAN_DATE_START_OF_GPS_TIME;
317  return 1;
318 }
319 
320 
322  const unsigned short utc_year,
323  const unsigned char utc_month,
324  const unsigned char utc_day,
325  const unsigned char utc_hour,
326  const unsigned char utc_minute,
327  const float utc_seconds,
328  double* julian_date
329  )
330 {
331  double y; // temp for year
332  double m; // temp for month
333  int result;
334 
335  // Check the input.
336  result = TIMECONV_IsUTCTimeValid( utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds );
337  if( result == 0 )
338  {
339  GNSS_ERROR_MSG( "TIMECONV_IsUTCTimeValid returned 0." );
340  return 0;
341  }
342 
343  if( utc_month <= 2 )
344  {
345  y = utc_year - 1;
346  m = utc_month + 12;
347  }
348  else
349  {
350  y = utc_year;
351  m = utc_month;
352  }
353 
354  *julian_date = (int)(365.25*y) + (int)(30.6001*(m+1.0)) + utc_day + utc_hour/24.0 + utc_minute/1440.0 + utc_seconds/86400.0 + 1720981.5;
355  return 1;
356 }
357 
358 
359 
361  const double julian_date,
362  const unsigned char utc_offset,
363  unsigned short* gps_week,
364  double* gps_tow
365  )
366 {
367  // Check the input.
368  if( julian_date < 0.0 )
369  {
370  GNSS_ERROR_MSG( "if( julian_date < 0.0 )" );
371  return 0;
372  }
373 
374  *gps_week = (unsigned short)((julian_date - TIMECONV_JULIAN_DATE_START_OF_GPS_TIME)/7.0); //
375 
376  *gps_tow = (julian_date - TIMECONV_JULIAN_DATE_START_OF_GPS_TIME)*SECONDS_IN_DAY; // seconds since start of gps time [s]
377  *gps_tow -= (*gps_week)*SECONDS_IN_WEEK; // seconds into the current week [s]
378 
379  // however, GPS time is ahead of utc time by the UTC offset (and thus the Julian date as well)
380  *gps_tow += utc_offset;
381  if( *gps_tow > SECONDS_IN_WEEK )
382  {
383  *gps_tow -= SECONDS_IN_WEEK;
384  *gps_week += 1;
385  }
386  return 1;
387 }
388 
389 
391  const double julian_date,
392  unsigned short* utc_year,
393  unsigned char* utc_month,
394  unsigned char* utc_day,
395  unsigned char* utc_hour,
396  unsigned char* utc_minute,
397  float* utc_seconds
398  )
399 {
400  int a, b, c, d, e; // temporary values
401 
402  unsigned short year;
403  unsigned char month;
404  unsigned char day;
405  unsigned char hour;
406  unsigned char minute;
407  unsigned char days_in_month = 0;
408  double td; // temporary double
409  double seconds;
410  int result;
411 
412  // Check the input.
413  if( julian_date < 0.0 )
414  {
415  GNSS_ERROR_MSG( "if( julian_date < 0.0 )" );
416  return 0;
417  }
418 
419  a = (int)(julian_date+0.5);
420  b = a + 1537;
421  c = (int)( ((double)b-122.1)/365.25 );
422  d = (int)(365.25*c);
423  e = (int)( ((double)(b-d))/30.6001 );
424 
425  td = b - d - (int)(30.6001*e) + fmod( julian_date+0.5, 1.0 ); // [days]
426  day = (unsigned char)td;
427  td -= day;
428  td *= 24.0; // [hours]
429  hour = (unsigned char)td;
430  td -= hour;
431  td *= 60.0; // [minutes]
432  minute = (unsigned char)td;
433  td -= minute;
434  td *= 60.0; // [s]
435  seconds = td;
436  month = (unsigned char)(e - 1 - 12*(int)(e/14));
437  year = (unsigned short)(c - 4715 - (int)( (7.0+(double)month) / 10.0 ));
438 
439  // check for rollover issues
440  if( seconds >= 60.0 )
441  {
442  seconds -= 60.0;
443  minute++;
444  if( minute >= 60 )
445  {
446  minute -= 60;
447  hour++;
448  if( hour >= 24 )
449  {
450  hour -= 24;
451  day++;
452 
453  result = TIMECONV_GetNumberOfDaysInMonth( year, month, &days_in_month );
454  if( result == 0 )
455  {
456  GNSS_ERROR_MSG( "TIMECONV_GetNumberOfDaysInMonth returned 0." );
457  return 0;
458  }
459 
460  if( day > days_in_month )
461  {
462  day = 1;
463  month++;
464  if( month > 12 )
465  {
466  month = 1;
467  year++;
468  }
469  }
470  }
471  }
472  }
473 
474  *utc_year = year;
475  *utc_month = month;
476  *utc_day = day;
477  *utc_hour = hour;
478  *utc_minute = minute;
479  *utc_seconds = (float)seconds;
480 
481  return 1;
482 }
483 
485  unsigned short utc_year,
486  unsigned char utc_month,
487  unsigned char utc_day,
488  unsigned char utc_hour,
489  unsigned char utc_minute,
490  float utc_seconds,
491  unsigned short* gps_week,
492  double* gps_tow
493  )
494 {
495  double julian_date=0.0;
496  unsigned char utc_offset=0;
497  int result;
498 
499  // Check the input.
500  result = TIMECONV_IsUTCTimeValid( utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds );
501  if( result == 0 )
502  {
503  GNSS_ERROR_MSG( "TIMECONV_IsUTCTimeValid returned 0." );
504  return 0;
505  }
506 
508  utc_year,
509  utc_month,
510  utc_day,
511  utc_hour,
512  utc_minute,
513  utc_seconds,
514  &julian_date );
515  if( result == 0 )
516  {
517  GNSS_ERROR_MSG( "TIMECONV_GetJulianDateFromUTCTime returned 0." );
518  return 0;
519  }
520 
521  result = TIMECONV_DetermineUTCOffset( julian_date, &utc_offset );
522  if( result == 0 )
523  {
524  GNSS_ERROR_MSG( "TIMECONV_DetermineUTCOffset returned 0." );
525  return 0;
526  }
527 
529  julian_date,
530  utc_offset,
531  gps_week,
532  gps_tow );
533  if( result == 0 )
534  {
535  GNSS_ERROR_MSG( "TIMECONV_GetGPSTimeFromJulianDate returned 0." );
536  return 0;
537  }
538 
539  return 1;
540 }
541 
542 
543 
545  unsigned short utc_year,
546  unsigned char utc_month,
547  unsigned char utc_day,
548  unsigned char utc_hour,
549  unsigned char utc_minute,
550  float utc_seconds,
551  unsigned short* gps_week,
552  double* gps_tow
553  )
554 {
555  double julian_date=0.0;
556  unsigned char utc_offset=0;
557  int result;
558 
559  // Check the input.
560  result = TIMECONV_IsUTCTimeValid( utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds );
561  if( result == 0 )
562  {
563  GNSS_ERROR_MSG( "TIMECONV_IsUTCTimeValid returned 0." );
564  return 0;
565  }
566 
568  utc_year,
569  utc_month,
570  utc_day,
571  utc_hour,
572  utc_minute,
573  utc_seconds,
574  &julian_date );
575  if( result == 0 )
576  {
577  GNSS_ERROR_MSG( "TIMECONV_GetJulianDateFromUTCTime returned 0." );
578  return 0;
579  }
580 
582  julian_date,
583  utc_offset,
584  gps_week,
585  gps_tow );
586  if( result == 0 )
587  {
588  GNSS_ERROR_MSG( "TIMECONV_GetGPSTimeFromJulianDate returned 0." );
589  return 0;
590  }
591 
592  return 1;
593 }
594 
595 
596 
598  unsigned short gps_week,
599  double gps_tow,
600  unsigned short* utc_year,
601  unsigned char* utc_month,
602  unsigned char* utc_day,
603  unsigned char* utc_hour,
604  unsigned char* utc_minute,
605  float* utc_seconds
606  )
607 {
608  double julian_date = 0.0;
609  unsigned char utc_offset = 0;
610  int i;
611  int result;
612 
613  if( gps_tow < 0.0 || gps_tow > 604800.0 )
614  {
615  GNSS_ERROR_MSG( "if( gps_tow < 0.0 || gps_tow > 604800.0 )" );
616  return 0;
617  }
618 
619  // iterate to get the right utc offset
620  for( i = 0; i < 4; i++ )
621  {
623  gps_week,
624  gps_tow,
625  utc_offset,
626  &julian_date );
627  if( result == 0 )
628  {
629  GNSS_ERROR_MSG( "TIMECONV_GetJulianDateFromGPSTime returned 0." );
630  return 0;
631  }
632 
633  result = TIMECONV_DetermineUTCOffset( julian_date, &utc_offset );
634  if( result == 0 )
635  {
636  GNSS_ERROR_MSG( "TIMECONV_DetermineUTCOffset returned 0." );
637  return 0;
638  }
639  }
640 
642  julian_date,
643  utc_year,
644  utc_month,
645  utc_day,
646  utc_hour,
647  utc_minute,
648  utc_seconds );
649  if( result == 0 )
650  {
651  GNSS_ERROR_MSG( "TIMECONV_GetUTCTimeFromJulianDate returned 0." );
652  return 0;
653  }
654 
655  return 1;
656 }
657 
658 
659 
661  double julian_date,
662  unsigned char* utc_offset
663  )
664 {
665  if( julian_date < 0.0 )
666  {
667  GNSS_ERROR_MSG( "if( julian_date < 0.0 )" );
668  return 0;
669  }
670 
671  if( julian_date < 2444786.5000 ) *utc_offset = 0;
672  else if( julian_date < 2445151.5000 ) *utc_offset = 1;
673  else if( julian_date < 2445516.5000 ) *utc_offset = 2;
674  else if( julian_date < 2446247.5000 ) *utc_offset = 3;
675  else if( julian_date < 2447161.5000 ) *utc_offset = 4;
676  else if( julian_date < 2447892.5000 ) *utc_offset = 5;
677  else if( julian_date < 2448257.5000 ) *utc_offset = 6;
678  else if( julian_date < 2448804.5000 ) *utc_offset = 7;
679  else if( julian_date < 2449169.5000 ) *utc_offset = 8;
680  else if( julian_date < 2449534.5000 ) *utc_offset = 9;
681  else if( julian_date < 2450083.5000 ) *utc_offset = 10;
682  else if( julian_date < 2450630.5000 ) *utc_offset = 11;
683  else if( julian_date < 2451179.5000 ) *utc_offset = 12;
684  else if( julian_date < 2453736.5000 ) *utc_offset = 13;
685  else *utc_offset = 14;
686 
687  return 1;
688 }
689 
690 
691 
692 
694  const unsigned short year,
695  const unsigned char month,
696  unsigned char* days_in_month
697  )
698 {
699  int is_a_leapyear;
700  unsigned char utmp = 0;
701 
702  is_a_leapyear = TIMECONV_IsALeapYear( year );
703 
704  switch(month)
705  {
706  case 1: utmp = TIMECONV_DAYS_IN_JAN; break;
707  case 2: if( is_a_leapyear ){ utmp = 29; }else{ utmp = 28; }break;
708  case 3: utmp = TIMECONV_DAYS_IN_MAR; break;
709  case 4: utmp = TIMECONV_DAYS_IN_APR; break;
710  case 5: utmp = TIMECONV_DAYS_IN_MAY; break;
711  case 6: utmp = TIMECONV_DAYS_IN_JUN; break;
712  case 7: utmp = TIMECONV_DAYS_IN_JUL; break;
713  case 8: utmp = TIMECONV_DAYS_IN_AUG; break;
714  case 9: utmp = TIMECONV_DAYS_IN_SEP; break;
715  case 10: utmp = TIMECONV_DAYS_IN_OCT; break;
716  case 11: utmp = TIMECONV_DAYS_IN_NOV; break;
717  case 12: utmp = TIMECONV_DAYS_IN_DEC; break;
718  default:
719  {
720  GNSS_ERROR_MSG( "unexpected default case." );
721  return 0;
722  break;
723  }
724  }
725 
726  *days_in_month = utmp;
727 
728  return 1;
729 }
730 
731 
732 
733 
734 int TIMECONV_IsALeapYear( const unsigned short year )
735 {
736  int is_a_leap_year = 0;
737 
738  if( (year%4) == 0 )
739  {
740  is_a_leap_year = 1;
741  if( (year%100) == 0 )
742  {
743  if( (year%400) == 0 )
744  {
745  is_a_leap_year = 1;
746  }
747  else
748  {
749  is_a_leap_year = 0;
750  }
751  }
752  }
753  if( is_a_leap_year )
754  {
755  return 1;
756  }
757  else
758  {
759  return 0;
760  }
761 }
762 
763 
764 
765 
766 
768  const unsigned short utc_year, // Universal Time Coordinated [year]
769  const unsigned char utc_month, // Universal Time Coordinated [1-12 months]
770  const unsigned char utc_day, // Universal Time Coordinated [1-31 days]
771  unsigned short* dayofyear // number of days into the year (1-366) [days]
772  )
773 {
774  unsigned char days_in_feb = 0;
775  int result;
776  result = TIMECONV_GetNumberOfDaysInMonth( utc_year, 2, &days_in_feb );
777  if( result == 0 )
778  {
779  GNSS_ERROR_MSG( "TIMECONV_GetNumberOfDaysInMonth returned 0." );
780  return 0;
781  }
782 
783  switch( utc_month )
784  {
785  case 1: *dayofyear = utc_day; break;
786  case 2: *dayofyear = (unsigned short)(TIMECONV_DAYS_IN_JAN + utc_day); break;
787  case 3: *dayofyear = (unsigned short)(TIMECONV_DAYS_IN_JAN + days_in_feb + utc_day); break;
788  case 4: *dayofyear = (unsigned short)(62 + days_in_feb + utc_day); break;
789  case 5: *dayofyear = (unsigned short)(92 + days_in_feb + utc_day); break;
790  case 6: *dayofyear = (unsigned short)(123 + days_in_feb + utc_day); break;
791  case 7: *dayofyear = (unsigned short)(153 + days_in_feb + utc_day); break;
792  case 8: *dayofyear = (unsigned short)(184 + days_in_feb + utc_day); break;
793  case 9: *dayofyear = (unsigned short)(215 + days_in_feb + utc_day); break;
794  case 10: *dayofyear = (unsigned short)(245 + days_in_feb + utc_day); break;
795  case 11: *dayofyear = (unsigned short)(276 + days_in_feb + utc_day); break;
796  case 12: *dayofyear = (unsigned short)(306 + days_in_feb + utc_day); break;
797  default:
798  {
799  GNSS_ERROR_MSG( "unexpected default case." );
800  return 0;
801  break;
802  }
803  }
804 
805  return 1;
806 }
807 
808 
810  const unsigned short year, // The year [year]
811  const unsigned short dayofyear, // The number of days into the year (1-366) [days]
812  unsigned short* gps_week,
813  double* gps_tow
814  )
815 {
816  int result;
817  double julian_date = 0;
818 
819  if( gps_week == NULL )
820  {
821  GNSS_ERROR_MSG( "if( gps_week == NULL )" );
822  return 0;
823  }
824  if( gps_tow == NULL )
825  {
826  GNSS_ERROR_MSG( "if( gps_tow == NULL )" );
827  return 0;
828  }
829  if( dayofyear > 366 )
830  {
831  GNSS_ERROR_MSG( "if( dayofyear > 366 )" );
832  return 0;
833  }
834 
836  year,
837  1,
838  1,
839  0,
840  0,
841  0,
842  &julian_date
843  );
844  if( result == 0 )
845  {
846  GNSS_ERROR_MSG( "TIMECONV_GetJulianDateFromUTCTime returned 0." );
847  return 0;
848  }
849 
850  julian_date += dayofyear - 1; // at the start of the day so -1.
851 
853  julian_date,
854  0,
855  gps_week,
856  gps_tow );
857  if( result == 0 )
858  {
859  GNSS_ERROR_MSG( "TIMECONV_GetGPSTimeFromJulianDate returned 0." );
860  return 0;
861  }
862 
863  return 1;
864 }
d
unsigned short WORD
Definition: integer.h:27
#define TIMECONV_DAYS_IN_APR
#define TIMECONV_DAYS_IN_DEC
#define SECONDS_IN_DAY
int TIMECONV_GetDayOfWeekFromJulianDate(const double julian_date, unsigned char *day_of_week)
Computes the day of the week from the Julian date.
int TIMECONV_GetGPSTimeFromJulianDate(const double julian_date, const unsigned char utc_offset, unsigned short *gps_week, double *gps_tow)
Computes GPS time from the Julian date.
int TIMECONV_GetJulianDateFromUTCTime(const unsigned short utc_year, const unsigned char utc_month, const unsigned char utc_day, const unsigned char utc_hour, const unsigned char utc_minute, const float utc_seconds, double *julian_date)
Computes the Julian date from UTC time.
GNSS core &#39;c&#39; function library: converting time information.
#define TIMECONV_DAYS_IN_JUL
int TIMECONV_DetermineUTCOffset(double julian_date, unsigned char *utc_offset)
This function is a look up table to determine the UTC offset from the Julian Date.
#define TIMECONV_DAYS_IN_NOV
#define NULL
Definition: nm_bsp.h:52
#define TIMECONV_DAYS_IN_JUN
#define GNSS_ERROR_MSG(errorMsg)
int TIMECONV_GetGPSTimeFromUTCTime(unsigned short utc_year, unsigned char utc_month, unsigned char utc_day, unsigned char utc_hour, unsigned char utc_minute, float utc_seconds, unsigned short *gps_week, double *gps_tow)
Computes GPS time from UTC time.
#define TIMECONV_DAYS_IN_OCT
static int TIMECONV_IsUTCTimeValid(const unsigned short utc_year, const unsigned char utc_month, const unsigned char utc_day, const unsigned char utc_hour, const unsigned char utc_minute, const float utc_seconds)
int TIMECONV_GetSystemTime(unsigned short *utc_year, unsigned char *utc_month, unsigned char *utc_day, unsigned char *utc_hour, unsigned char *utc_minute, float *utc_seconds, unsigned char *utc_offset, double *julian_date, unsigned short *gps_week, double *gps_tow)
Obtains the UTC time, GPS time, and Julian date from PC system time.
#define TIMECONV_DAYS_IN_MAY
int TIMECONV_GetNumberOfDaysInMonth(const unsigned short year, const unsigned char month, unsigned char *days_in_month)
Determines the number of days in a month, given the month and year.
int TIMECONV_IsALeapYear(const unsigned short year)
Determines if the given year is a leap year.
int TIMECONV_GetUTCTimeFromGPSTime(unsigned short gps_week, double gps_tow, unsigned short *utc_year, unsigned char *utc_month, unsigned char *utc_day, unsigned char *utc_hour, unsigned char *utc_minute, float *utc_seconds)
Computes UTC time from GPS time.
#define TIMECONV_DAYS_IN_JAN
#define TIMECONV_JULIAN_DATE_START_OF_PC_TIME
#define SECONDS_IN_WEEK
#define TIMECONV_DAYS_IN_SEP
int TIMECONV_GetGPSTimeFromRinexTime(unsigned short utc_year, unsigned char utc_month, unsigned char utc_day, unsigned char utc_hour, unsigned char utc_minute, float utc_seconds, unsigned short *gps_week, double *gps_tow)
Computes GPS time from RINEX time. RINEX time looks like UTC but it is GPS time in year...
#define TIMECONV_DAYS_IN_AUG
#define TIMECONV_JULIAN_DATE_START_OF_GPS_TIME
#define TIMECONV_DAYS_IN_MAR
int TIMECONV_GetUTCTimeFromJulianDate(const double julian_date, unsigned short *utc_year, unsigned char *utc_month, unsigned char *utc_day, unsigned char *utc_hour, unsigned char *utc_minute, float *utc_seconds)
Computes UTC time from the Julian date.
int TIMECONV_GetGPSTimeFromYearAndDayOfYear(const unsigned short year, const unsigned short dayofyear, unsigned short *gps_week, double *gps_tow)
Determines the GPS time of the start of a day from the day of year and the year.
int TIMECONV_GetDayOfYear(const unsigned short utc_year, const unsigned char utc_month, const unsigned char utc_day, unsigned short *dayofyear)
Determines the day of year given the year, month, and day.
int TIMECONV_GetJulianDateFromGPSTime(const unsigned short gps_week, const double gps_tow, const unsigned char utc_offset, double *julian_date)
Computes the Julian date from GPS time.


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:05