time_conversion.c File Reference


Detailed Description

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

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

"LICENSE INFORMATION"
Copyright (c) 2007, refer to 'author' doxygen tags
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file time_conversion.c.

#include <sys/timeb.h>
#include <time.h>
#include <math.h>
#include "gnss_error.h"
#include "time_conversion.h"
#include "constants.h"

Go to the source code of this file.

Functions

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


Function Documentation

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
Remarks:
  • This function must be updated when the next UTC *utc_offset step occurs. Current max is (13).
REFERENCES

"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_date  Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
utc_offset  Integer seconds that GPS is ahead of UTC time, always positive [s], obtained from a look up table

Definition at line 677 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
REFERENCES
http://en.wikipedia.org/wiki/Julian_day
Parameters:
julian_date  Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
day_of_week  0-Sunday, 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday [].

Definition at line 279 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
Remarks:
(1) Performed independant comparison with http://www.mbari.org/staff/coletti/doytable.html

Definition at line 784 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
REFERENCES
Parameters:
julian_date  Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
utc_offset  Integer seconds that GPS is ahead of UTC time, always positive [s]
gps_week  GPS week (0-1024+) [week]
gps_tow  GPS time of week [s]

Definition at line 377 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(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_year  Universal Time Coordinated [year]
utc_month  Universal Time Coordinated [1-12 months]
utc_day  Universal Time Coordinated [1-31 days]
utc_hour  Universal Time Coordinated [hours]
utc_minute  Universal Time Coordinated [minutes]
utc_seconds  Universal Time Coordinated [s]
gps_week  GPS week (0-1024+) [week]
gps_tow  GPS time of week (0-604800.0) [s]

Definition at line 561 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
Remarks:
(1) The utc offset is determined automatically from a look up table
REFERENCES
Parameters:
utc_year  Universal Time Coordinated [year]
utc_month  Universal Time Coordinated [1-12 months]
utc_day  Universal Time Coordinated [1-31 days]
utc_hour  Universal Time Coordinated [hours]
utc_minute  Universal Time Coordinated [minutes]
utc_seconds  Universal Time Coordinated [s]
gps_week  GPS week (0-1024+) [week]
gps_tow  GPS time of week (0-604800.0) [s]

Definition at line 501 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
Parameters:
gps_week  GPS week (0-1024+) [week]
gps_tow  GPS time of week (0-604800.0) [s]

Definition at line 826 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
REFERENCES
Parameters:
gps_week  GPS week (0-1024+) [week]
gps_tow  GPS time of week (0-604800.0) [s]
utc_offset  Integer seconds that GPS is ahead of UTC time, always positive [s]
julian_date  Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]

Definition at line 319 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
Remarks:
REFERENCES
Parameters:
utc_year  Universal Time Coordinated [year]
utc_month  Universal Time Coordinated [1-12 months]
utc_day  Universal Time Coordinated [1-31 days]
utc_hour  Universal Time Coordinated [hours]
utc_minute  Universal Time Coordinated [minutes]
utc_seconds  Universal Time Coordinated [s]
julian_date  Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]

Definition at line 338 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
REFERENCES
Parameters:
year  Universal Time Coordinated [year]
month  Universal Time Coordinated [1-12 months]
days_in_month  Days in the specified month [1-28|29|30|31 days]

Definition at line 710 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
Remarks:
(1) Millisecond time is obtained
Parameters:
utc_year  Universal Time Coordinated [year]
utc_month  Universal Time Coordinated [1-12 months]
utc_day  Universal Time Coordinated [1-31 days]
utc_hour  Universal Time Coordinated [hours]
utc_minute  Universal Time Coordinated [minutes]
utc_seconds  Universal Time Coordinated [s]
utc_offset  Integer seconds that GPS is ahead of UTC time, always positive [s], obtained from a look up table
julian_date  Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
gps_week  GPS week (0-1024+) [week]
gps_tow  GPS time of week (0-604800.0) [s]

Definition at line 136 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
Remarks:
  • The utc offset is determined automatically from a look up table
REFERENCES
Parameters:
gps_week  GPS week (0-1024+) [week]
gps_tow  GPS time of week (0-604800.0) [s]
utc_year  Universal Time Coordinated [year]
utc_month  Universal Time Coordinated [1-12 months]
utc_day  Universal Time Coordinated [1-31 days]
utc_hour  Universal Time Coordinated [hours]
utc_minute  Universal Time Coordinated [minutes]
utc_seconds  Universal Time Coordinated [s]

Definition at line 614 of file time_conversion.c.

BOOL 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:
TRUE(1) if successful, FALSE(0) otherwise.
REFERENCES
Parameters:
julian_date  Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
utc_year  Universal Time Coordinated [year]
utc_month  Universal Time Coordinated [1-12 months]
utc_day  Universal Time Coordinated [1-31 days]
utc_hour  Universal Time Coordinated [hours]
utc_minute  Universal Time Coordinated [minutes]
utc_seconds  Universal Time Coordinated [s]

Definition at line 407 of file time_conversion.c.

BOOL 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:
TRUE(1) if the given year is a leap year, FALSE(0) otherwise

Definition at line 751 of file time_conversion.c.

SourceForge.net Logo