Macros | Functions
time_conversion.c File Reference

GNSS core 'c' function library: converting time information. More...

#include <sys/timeb.h>
#include <time.h>
#include <math.h>
#include "time_conversion.h"
#include "ISConstants.h"
Include dependency graph for time_conversion.c:

Go to the source code of this file.

Macros

#define TIMECONV_DAYS_IN_APR   30
 
#define TIMECONV_DAYS_IN_AUG   31
 
#define TIMECONV_DAYS_IN_DEC   31
 
#define TIMECONV_DAYS_IN_JAN   31
 
#define TIMECONV_DAYS_IN_JUL   31
 
#define TIMECONV_DAYS_IN_JUN   30
 
#define TIMECONV_DAYS_IN_MAR   31
 
#define TIMECONV_DAYS_IN_MAY   31
 
#define TIMECONV_DAYS_IN_NOV   30
 
#define TIMECONV_DAYS_IN_OCT   31
 
#define TIMECONV_DAYS_IN_SEP   30
 
#define TIMECONV_JULIAN_DATE_START_OF_GPS_TIME   (2444244.5)
 
#define TIMECONV_JULIAN_DATE_START_OF_PC_TIME   (2440587.5)
 

Functions

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. More...
 
int TIMECONV_GetDayOfWeekFromJulianDate (const double julian_date, unsigned char *day_of_week)
 Computes the day of the week from the Julian date. More...
 
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. More...
 
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. More...
 
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, month, day, hours, minutes, seconds. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int TIMECONV_IsALeapYear (const unsigned short year)
 Determines if the given year is a leap year. More...
 
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)
 

Detailed Description

GNSS core 'c' function library: converting time information.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-07-30

REFERENCES

Definition in file time_conversion.c.

Macro Definition Documentation

◆ TIMECONV_DAYS_IN_APR

#define TIMECONV_DAYS_IN_APR   30

Definition at line 58 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_AUG

#define TIMECONV_DAYS_IN_AUG   31

Definition at line 62 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_DEC

#define TIMECONV_DAYS_IN_DEC   31

Definition at line 66 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_JAN

#define TIMECONV_DAYS_IN_JAN   31

Definition at line 56 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_JUL

#define TIMECONV_DAYS_IN_JUL   31

Definition at line 61 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_JUN

#define TIMECONV_DAYS_IN_JUN   30

Definition at line 60 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_MAR

#define TIMECONV_DAYS_IN_MAR   31

Definition at line 57 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_MAY

#define TIMECONV_DAYS_IN_MAY   31

Definition at line 59 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_NOV

#define TIMECONV_DAYS_IN_NOV   30

Definition at line 65 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_OCT

#define TIMECONV_DAYS_IN_OCT   31

Definition at line 64 of file time_conversion.c.

◆ TIMECONV_DAYS_IN_SEP

#define TIMECONV_DAYS_IN_SEP   30

Definition at line 63 of file time_conversion.c.

◆ TIMECONV_JULIAN_DATE_START_OF_GPS_TIME

#define TIMECONV_JULIAN_DATE_START_OF_GPS_TIME   (2444244.5)

Definition at line 54 of file time_conversion.c.

◆ TIMECONV_JULIAN_DATE_START_OF_PC_TIME

#define TIMECONV_JULIAN_DATE_START_OF_PC_TIME   (2440587.5)

Definition at line 55 of file time_conversion.c.

Function Documentation

◆ TIMECONV_DetermineUTCOffset()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.
Remarks
  • This function must be updated when the next UTC *utc_offset step occurs. Current max is (13).

REFERENCES

  • Raquet, J. F. (2002), GPS Receiver Design Lecture Notes. Geomatics Engineering, University of Calgary Graduate Course.
    "Offset Table"
    UTCOffset, UTC Date, Julian Date [days]
    0, Jan 06 1980 00:00:00.0, 2444244.5000
    1, Jul 01 1981 00:00:00.0, 2444786.5000
    2, Jul 01 1982 00:00:00.0, 2445151.5000
    3, Jul 01 1983 00:00:00.0, 2445516.5000
    4, Jul 01 1985 00:00:00.0, 2446247.5000
    5, Jan 01 1988 00:00:00.0, 2447161.5000
    6, Jan 01 1990 00:00:00.0, 2447892.5000
    7, Jan 01 1991 00:00:00.0, 2448257.5000
    8, Jul 01 1992 00:00:00.0, 2448804.5000
    9, Jul 01 1993 00:00:00.0, 2449169.5000
    10, Jul 01 1994 00:00:00.0, 2449534.5000
    11, Jan 01 1996 00:00:00.0, 2450083.5000
    12, Jul 01 1997 00:00:00.0, 2450630.5000
    13, Jan 01 1999 00:00:00.0, 2451179.5000
    14, Jan 01 2006 00:00:00.0, 2453736.5000
Parameters
julian_dateNumber of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
utc_offsetInteger seconds that GPS is ahead of UTC time, always positive [s], obtained from a look up table

Definition at line 660 of file time_conversion.c.

◆ TIMECONV_GetDayOfWeekFromJulianDate()

int TIMECONV_GetDayOfWeekFromJulianDate ( const double  julian_date,
unsigned char *  day_of_week 
)

Computes the day of the week from the Julian date.

Author
Glenn D. MacGougan (GDM)
Date
2008-12-03
Since
2008-12-03
Returns
1(1) if successful, 0(0) otherwise.

REFERENCES
http://en.wikipedia.org/wiki/Julian_day

Parameters
julian_dateNumber of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
day_of_week0-Sunday, 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday [].

Definition at line 262 of file time_conversion.c.

◆ TIMECONV_GetDayOfYear()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.
Remarks
(1) Performed independant comparison with http://www.mbari.org/staff/coletti/doytable.html

Definition at line 767 of file time_conversion.c.

◆ TIMECONV_GetGPSTimeFromJulianDate()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.

REFERENCES

  • Hofmann-Wellenhof, B., H. Lichtenegger, and J. Collins (1994). GPS Theory and Practice, Third, revised edition. Springer-Verlag, Wien New York. pp. 38-42
Parameters
julian_dateNumber of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
utc_offsetInteger seconds that GPS is ahead of UTC time, always positive [s]
gps_weekGPS week (0-1024+) [week]
gps_towGPS time of week [s]

Definition at line 360 of file time_conversion.c.

◆ TIMECONV_GetGPSTimeFromRinexTime()

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, month, day, hours, minutes, seconds.

Author
Glenn D. MacGougan (GDM)
Date
2007-12-07
Since
2007-12-07
Returns
1(1) if successful, 0(0) otherwise.
Remarks
  • There is no UTC offset to apply
  • The RINEX time system must be the GPS Time system to use this function.

REFERENCES

Parameters
utc_yearUniversal Time Coordinated [year]
utc_monthUniversal Time Coordinated [1-12 months]
utc_dayUniversal Time Coordinated [1-31 days]
utc_hourUniversal Time Coordinated [hours]
utc_minuteUniversal Time Coordinated [minutes]
utc_secondsUniversal Time Coordinated [s]
gps_weekGPS week (0-1024+) [week]
gps_towGPS time of week (0-604800.0) [s]

Definition at line 544 of file time_conversion.c.

◆ TIMECONV_GetGPSTimeFromUTCTime()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.
Remarks
(1) The utc offset is determined automatically from a look up table

REFERENCES

  • Hofmann-Wellenhof, B., H. Lichtenegger, and J. Collins (1994). GPS Theory and Practice, Third, revised edition. Springer-Verlag, Wien New York. pp. 38-42
Parameters
utc_yearUniversal Time Coordinated [year]
utc_monthUniversal Time Coordinated [1-12 months]
utc_dayUniversal Time Coordinated [1-31 days]
utc_hourUniversal Time Coordinated [hours]
utc_minuteUniversal Time Coordinated [minutes]
utc_secondsUniversal Time Coordinated [s]
gps_weekGPS week (0-1024+) [week]
gps_towGPS time of week (0-604800.0) [s]

Definition at line 484 of file time_conversion.c.

◆ TIMECONV_GetGPSTimeFromYearAndDayOfYear()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-12-07
Since
2007-12-07
Returns
1(1) if successful, 0(0) otherwise.
Parameters
gps_weekGPS week (0-1024+) [week]
gps_towGPS time of week (0-604800.0) [s]

Definition at line 809 of file time_conversion.c.

◆ TIMECONV_GetJulianDateFromGPSTime()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.

REFERENCES

  • Hofmann-Wellenhof, B., H. Lichtenegger, and J. Collins (1994). GPS Theory and Practice, Third, revised edition. Springer-Verlag, Wien New York. pp. 38-42
Parameters
gps_weekGPS week (0-1024+) [week]
gps_towGPS time of week (0-604800.0) [s]
utc_offsetInteger seconds that GPS is ahead of UTC time, always positive [s]
julian_dateNumber of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]

Definition at line 302 of file time_conversion.c.

◆ TIMECONV_GetJulianDateFromUTCTime()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.
Remarks
Parameters
utc_yearUniversal Time Coordinated [year]
utc_monthUniversal Time Coordinated [1-12 months]
utc_dayUniversal Time Coordinated [1-31 days]
utc_hourUniversal Time Coordinated [hours]
utc_minuteUniversal Time Coordinated [minutes]
utc_secondsUniversal Time Coordinated [s]
julian_dateNumber of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]

Definition at line 321 of file time_conversion.c.

◆ TIMECONV_GetNumberOfDaysInMonth()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.

REFERENCES

  • Hofmann-Wellenhof, B., H. Lichtenegger, and J. Collins (1994). GPS Theory and Practice, Third, revised edition. Springer-Verlag, Wien New York. pp. 38-42
Parameters
yearUniversal Time Coordinated [year]
monthUniversal Time Coordinated [1-12 months]
days_in_monthDays in the specified month [1-28|29|30|31 days]

Definition at line 693 of file time_conversion.c.

◆ TIMECONV_GetSystemTime()

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.

Author
Glenn D. MacGougan (GDM)
Date
2006-11-10
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.
Remarks
(1) Millisecond time is obtained
Parameters
utc_yearUniversal Time Coordinated [year]
utc_monthUniversal Time Coordinated [1-12 months]
utc_dayUniversal Time Coordinated [1-31 days]
utc_hourUniversal Time Coordinated [hours]
utc_minuteUniversal Time Coordinated [minutes]
utc_secondsUniversal Time Coordinated [s]
utc_offsetInteger seconds that GPS is ahead of UTC time, always positive [s], obtained from a look up table
julian_dateNumber of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
gps_weekGPS week (0-1024+) [week]
gps_towGPS time of week (0-604800.0) [s]

Definition at line 128 of file time_conversion.c.

◆ TIMECONV_GetUTCTimeFromGPSTime()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.
Remarks
  • The utc offset is determined automatically from a look up table

REFERENCES

  • Hofmann-Wellenhof, B., H. Lichtenegger, and J. Collins (1994). GPS Theory and Practice, Third, revised edition. Springer-Verlag, Wien New York. pp. 38-42
Parameters
gps_weekGPS week (0-1024+) [week]
gps_towGPS time of week (0-604800.0) [s]
utc_yearUniversal Time Coordinated [year]
utc_monthUniversal Time Coordinated [1-12 months]
utc_dayUniversal Time Coordinated [1-31 days]
utc_hourUniversal Time Coordinated [hours]
utc_minuteUniversal Time Coordinated [minutes]
utc_secondsUniversal Time Coordinated [s]

Definition at line 597 of file time_conversion.c.

◆ TIMECONV_GetUTCTimeFromJulianDate()

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.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if successful, 0(0) otherwise.

REFERENCES

  • Hofmann-Wellenhof, B., H. Lichtenegger, and J. Collins (1994). GPS Theory and Practice, Third, revised edition. Springer-Verlag, Wien New York. pp. 38-42
Parameters
julian_dateNumber of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
utc_yearUniversal Time Coordinated [year]
utc_monthUniversal Time Coordinated [1-12 months]
utc_dayUniversal Time Coordinated [1-31 days]
utc_hourUniversal Time Coordinated [hours]
utc_minuteUniversal Time Coordinated [minutes]
utc_secondsUniversal Time Coordinated [s]

Definition at line 390 of file time_conversion.c.

◆ TIMECONV_IsALeapYear()

int TIMECONV_IsALeapYear ( const unsigned short  year)

Determines if the given year is a leap year.

Author
Glenn D. MacGougan (GDM)
Date
2007-11-29
Since
2005-08-22
Returns
1(1) if the given year is a leap year, 0(0) otherwise
  • Hofmann-Wellenhof, B., H. Lichtenegger, and J. Collins (1994). GPS Theory and Practice, Third, revised edition. Springer-Verlag, Wien New York. pp. 38-42

Definition at line 734 of file time_conversion.c.

◆ TIMECONV_IsUTCTimeValid()

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 
)
static
Parameters
utc_yearUniversal Time Coordinated [year]
utc_monthUniversal Time Coordinated [1-12 months]
utc_dayUniversal Time Coordinated [1-31 days]
utc_hourUniversal Time Coordinated [hours]
utc_minuteUniversal Time Coordinated [minutes]
utc_secondsUniversal Time Coordinated [s]

Definition at line 81 of file time_conversion.c.



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