26 #include <lal/LALAtomicDatatypes.h>
27 #include <lal/XLALError.h>
30 #define gmtime_r(timep, result) memcpy((result), gmtime(timep), sizeof(struct tm))
115 for ( leap = 1; leap <
numleaps; ++leap )
116 if ( gpssec ==
leaps[leap].gpssec )
127 if ( gpssec <
leaps[0].gpssec )
129 XLALPrintError(
"XLAL Error - Don't know leap seconds before GPS time %d\n",
135 for ( leap = 1; leap <
numleaps; ++leap )
136 if ( gpssec <
leaps[leap].gpssec )
153 leapGPS = leapTAI - 19;
169 if ( jd <
leaps[0].jd )
171 XLALPrintError(
"XLAL Error - Don't know leap seconds before Julian Day %9.1f\n",
leaps[0].jd );
176 for ( leap = 1; leap <
numleaps; ++leap )
177 if ( jd <
leaps[leap].jd )
196 int sec = utc->tm_sec;
197 int min = utc->tm_min;
198 int hour = utc->tm_hour;
199 int mday = utc->tm_mday;
200 int mon = utc->tm_mon;
201 int year_requested = utc->tm_year;
205 int mon_remainder = mon % 12;
206 int negative_mon_remainder = mon_remainder < 0;
207 int mon_years = mon / 12 - negative_mon_remainder;
208 long int lyear_requested = year_requested;
209 long int year = lyear_requested + mon_years;
212 const unsigned short int __mon_yday[2][13] =
215 { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
217 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
224 int corr_year = 1900 + year - (mon < 2);
226 + (365 * (year - 70))
228 - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0)
229 + (((corr_year / 4) / 25) / 4)
232 wday = ((wday % 7) + 7) % 7;
240 || ((year / 100) & 3) == (- (1900 / 100) & 3)));
244 int mon_yday = ((__mon_yday[leapyear]
245 [mon_remainder + 12 * negative_mon_remainder])
247 long int lmday = mday;
248 long int yday = mon_yday + lmday;
277 const time_t tm_sec = (time_t)utc->tm_sec;
278 const time_t tm_min = (time_t)utc->tm_min;
279 const time_t tm_hour = (time_t)utc->tm_hour;
280 const time_t tm_yday = (time_t)utc->tm_yday;
281 const time_t tm_year = (time_t)utc->tm_year;
283 return tm_sec + tm_min * 60 + tm_hour * 3600 +
284 tm_yday * 86400 + (tm_year - 70) * 31536000 +
285 ((tm_year - 69) / 4) * 86400 -
286 ((tm_year - 1) / 100) * 86400 +
287 ((tm_year + 299) / 400) * 86400;
303 struct tm utc_filled = *utc;
318 if ( utc->tm_sec == 60 )
321 if ( ((
INT4)gpssec) != gpssec ) {
323 strftime(buf,
sizeof(buf),
"%Y-%m-%d %H:%M:%S", utc);
327 return ((
INT4)gpssec);
348 memset( utc, 0,
sizeof( *utc ) );
409 const int sec_per_day = 60 * 60 * 24;
410 int year, month, day, sec;
414 if ( civil->tm_year <= 0 )
420 year = civil->tm_year + 1900;
421 month = civil->tm_mon + 1;
422 day = civil->tm_mday;
423 sec = civil->tm_sec + 60*(civil->tm_min + 60*(civil->tm_hour));
425 jd = 367*year - 7*(year + (month + 9)/12)/4 + 275*month/9 + day + 1721014;
#define gmtime_r(timep, result)
int XLALPrintError(const char *fmt,...)
static const struct leaps_table leaps[]
static const int numleaps
#define XLAL_JD_TO_MJD(jd)
Modified Julian Day for specified civil time structure.
#define XLAL_EPOCH_UNIX_GPS
The UNIX time of the GPS origin epoch.
#define XLAL_EPOCH_GPS_TAI_UTC
Leap seconds (TAI-UTC) on the GPS epoch (1980 JAN 6 0h UTC)
#define XLAL_INIT_MEM(x)
MACRO to initialize arbitrary variable 'x' to zero.
double REAL8
Double precision real floating-point number (8 bytes).
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
int32_t INT4
Four-byte signed integer.
REAL8 XLALConvertCivilTimeToJD(const struct tm *civil)
Returns the Julian Day (JD) corresponding to the civil date and time given in a broken down time stru...
int XLALGPSLeapSeconds(INT4 gpssec)
Returns the leap seconds GPS-UTC at a given GPS second.
REAL8 XLALJulianDay(const struct tm *civil)
INT4 XLALUTCToGPS(const struct tm *utc)
Returns the GPS seconds since the GPS epoch for a specified UTC time structure.
int XLALLeapSeconds(INT4 gpssec)
Returns the leap seconds TAI-UTC at a given GPS second.
time_t XLALSecondsSinceUnixEpoch(const struct tm *utc)
Compute Unix epoch time: seconds since 1970 January 1 0h UTC (POSIX:2001 definition of Unix Epoch).
struct tm * XLALFillUTC(struct tm *utc)
Fill in derived fields, e.g.
static int delta_tai_utc(INT4 gpssec)
int XLALLeapSecondsUTC(const struct tm *utc)
Returns the leap seconds TAI-UTC for a given UTC broken down time.
REAL8 XLALConvertCivilTimeToMJD(const struct tm *civil)
Returns the Modified Julian Day MJD corresponding to the civil date and time given in a broken down t...
INT4 XLALModifiedJulianDay(const struct tm *civil)
struct tm * XLALGPSToUTC(struct tm *utc, INT4 gpssec)
Returns a pointer to a tm structure representing the time specified in seconds since the GPS epoch.
#define XLAL_ERROR_REAL8(...)
Macro to invoke a failure from a XLAL routine returning a REAL8.
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
#define XLAL_PRINT_DEPRECATION_WARNING(replacement)
Prints a deprecation warning at the "warning" verbosity level.
#define XLAL_IS_REAL8_FAIL_NAN(val)
Tests if val is a XLAL REAL8 failure NaN.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EDOM
Input domain error.
@ XLAL_EINVAL
Invalid argument.