int correctionTest(void) { gpstk::TestUtil testFramework("TimeSystem", "Correction", __FILE__, __LINE__); std::string testMesg; gpstk::TimeSystem GPStime(2); gpstk::TimeSystem GLOtime(3); gpstk::TimeSystem GALtime(4); gpstk::TimeSystem QZStime(5); gpstk::TimeSystem BDTtime(6); gpstk::TimeSystem UTCtime(7); gpstk::TimeSystem TAItime(8); gpstk::TimeSystem TTtime(9); gpstk::TimeSystem TDBtime(10); //------------------------------------------------------------------------- //Check conversion from any given time system to UTC and back //------------------------------------------------------------------------- testMesg = "Conversion from UTC time to GPS time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(UTCtime, GPStime, 1990, 11, 6) - 6) < eps, testMesg, __LINE__); testMesg = "Conversion from GPS time to UTC time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(GPStime, UTCtime, 2004, 11, 16) + 13) < eps, testMesg, __LINE__); testMesg = "Conversion from UTC time to GLO time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(UTCtime, GLOtime, 1992, 10, 3) - 0) < eps, testMesg, __LINE__); testMesg = "Conversion from GLO time to UTC time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(GLOtime, UTCtime, 1995, 5, 10) - 0) < eps, testMesg, __LINE__); testMesg = "Conversion from UTC time to GAL time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(UTCtime, GALtime, 1997, 7, 25) - 12) < eps, testMesg, __LINE__); testMesg = "Conversion from GAL time to UTC time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(GALtime, UTCtime, 2008, 6, 5) + 14) < eps, testMesg, __LINE__); // QZSS can't be converted //testMesg = "Conversion from UTC time to QZS time was incorrect"; //testFramework.assert(std::abs(gpstk::TimeSystem::Correction(UTCtime, QZStime, 1985, 8, 10) - 4) < eps, testMesg, __LINE__); //testMesg = "Conversion from QZS time to UTC time was incorrect"; //testFramework.assert(std::abs(gpstk::TimeSystem::Correction(QZStime, UTCtime, 2010, 2, 14) - 15) < eps, testMesg, __LINE__); testMesg = "Conversion from UTC time to BDT time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(UTCtime, BDTtime, 2001, 9, 21) - 0) < eps, testMesg, __LINE__); testMesg = "Conversion from BDT time to UTC time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(BDTtime, UTCtime, 2012, 8, 27) - 0) < eps, testMesg, __LINE__); testMesg = "Conversion from UTC time to TAI time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(UTCtime, TAItime, 2014, 6, 1) - 35) < eps, testMesg, __LINE__); testMesg = "Conversion from TAI time to UTC time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(TAItime, UTCtime, 2015, 1, 1) + 35) < eps, testMesg, __LINE__); testMesg = "Conversion from UTC time to TT time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(UTCtime, TTtime, 2005, 4, 31) - (13 + 51.184)) < eps, testMesg, __LINE__); testMesg = "Conversion from TT time to UTC time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(TTtime, UTCtime, 1990, 7, 21) + (6 + 51.184) ) < eps, testMesg, __LINE__); //reference section B of astronomical almanac for TDB conversion testMesg = "Conversion from UTC time to TDB time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(UTCtime, TDBtime, 2007, 12, 25) - 65.1840299405112091335467994213104248046875) < eps, testMesg, __LINE__); testMesg = "Conversion from TDB time to UTC time was incorrect"; testFramework.assert(std::abs(gpstk::TimeSystem::Correction(TDBtime, UTCtime, 1991, 4, 25) + 58.1838658094272460630236309953033924102783203125) < eps, testMesg, __LINE__); return testFramework.countFails(); }
int wwvbDecode ( clkInfoT* clock, time_f minstart ) { struct tm dectime; time_t dectimet; wwvbDump ( clock ); if ( !DATA_OK(1) ) return -1; memset ( &dectime, 0, sizeof(dectime) ); dectime.tm_year = wwvbGetBCD ( clock, 44, 10 ) + CENTURY - 1900; dectime.tm_mon = 1; dectime.tm_mday = wwvbGetBCD ( clock, 22, 12 ); dectime.tm_hour = wwvbGetBCD ( clock, 12, 7 ); dectime.tm_min = wwvbGetBCD ( clock, 1, 8 ); dectime.tm_sec = 0; dectime.tm_isdst = 0; //time is always UTC... (although there are bits for summer time) //NOTE: decoding this depends on a mktime() which will normalize day numbers correctly if ( (dectime.tm_mday < 1) || (dectime.tm_mday > 366) ) return -1; if ( dectime.tm_hour > 23 ) return -1; if ( dectime.tm_min > 60 ) return -1; loggerf ( LOGGER_DEBUG, "WWVB time: %04d-%03d %02d:%02d %s%s\n", dectime.tm_year+1900, dectime.tm_mday, dectime.tm_hour, dectime.tm_min, GET(55)?" leap year":"", GET(56)?" leap second soon":"" ); // setenv ( "TZ", "", 1 ); // // dectimet = mktime ( &dectime ); dectimet = UTCtime ( &dectime ); if ( dectimet == (time_t)(-1) ) return -1; clock->pctime = minstart; clock->radiotime = dectimet + clock->fudgeoffset; clock->radioleap = GET(56) ? LEAP_ADDSECOND : LEAP_NOWARNING; clock->secondssincetime = 0; return 0; }