diff --git a/packet.cpp b/packet.cpp index 1d66148..5f3062d 100644 --- a/packet.cpp +++ b/packet.cpp @@ -128,28 +128,27 @@ void Packet::SetMRAG(uint8_t mag, uint8_t row) */ bool Packet::get_offset_time(char* str) { - char strTime[6]; - time_t rawtime; - struct tm tmGMT; - time( &rawtime ); + char strTime[6]; + time_t rawtime = time(nullptr); + struct tm *tmGMT; - // What is our offset in seconds? - int offset=((str[3]-'0')*10+str[4]-'0')*30*60; // @todo We really ought to validate this + // What is our offset in seconds? + int offset=((str[3]-'0')*10+str[4]-'0')*30*60; // @todo We really ought to validate this - // Is it negative (west of us?) - if (str[2]=='-') - offset=-offset; - else - if (str[2]!='+') return false; // Must be + or - + // Is it negative (west of us?) + if (str[2]=='-') + offset=-offset; + else + if (str[2]!='+') return false; // Must be + or - - // Add the offset to the time value - rawtime+=offset; + // Add the offset to the time value + rawtime+=offset; - gmtime_r(&rawtime, &tmGMT); + tmGMT = gmtime(&rawtime); - strftime(strTime, 21, "%H:%M", &tmGMT); - stringToBytes(str,strTime,5); - return true; + strftime(strTime, 21, "%H:%M", tmGMT); + stringToBytes(str,strTime,5); + return true; } /* Ideally we would set _packet[0] for other hardware, or _packet[3] for Alistair Buxton raspi-teletext/ diff --git a/packet830.cpp b/packet830.cpp index 7f86367..bef50f5 100644 --- a/packet830.cpp +++ b/packet830.cpp @@ -21,10 +21,10 @@ Packet830::~Packet830() Packet* Packet830::GetPacket(Packet* p) { - time_t timeRaw; + time_t timeRaw = time(nullptr); time_t timeLocal; - struct tm tmLocal; - struct tm tmGMT; + struct tm *tmLocal; + struct tm *tmGMT; int offsetHalfHours, year, month, day, hour, minute, second; uint32_t modifiedJulianDay; @@ -59,14 +59,13 @@ Packet* Packet830::GetPacket(Packet* p) val[8] = _vbi_bit_reverse[nic & 0xFF]; /* calculate number of seconds local time is offset from UTC */ - time(&timeRaw); - localtime_r(&timeRaw, &tmLocal); + tmLocal = localtime(&timeRaw); /* convert tmLocal into a timestamp without correcting for timezones and summertime */ #ifdef WIN32 - timeLocal = _mkgmtime(&tmLocal); + timeLocal = _mkgmtime(tmLocal); #else - timeLocal = timegm(&tmLocal); + timeLocal = timegm(tmLocal); #endif offsetHalfHours = difftime(timeLocal, timeRaw) / 1800; @@ -76,13 +75,13 @@ Packet* Packet830::GetPacket(Packet* p) val[9] = ((offsetHalfHours < 0) ? 0xC1 : 0x81) | ((abs(offsetHalfHours) & 0x1F) << 1); // get the time current UTC time into separate variables - gmtime_r(&timeRaw, &tmGMT); - year = tmGMT.tm_year + 1900; - month = tmGMT.tm_mon + 1; - day = tmGMT.tm_mday; - hour = tmGMT.tm_hour; - minute = tmGMT.tm_min; - second = tmGMT.tm_sec; + tmGMT = gmtime(&timeRaw); + year = tmGMT->tm_year + 1900; + month = tmGMT->tm_mon + 1; + day = tmGMT->tm_mday; + hour = tmGMT->tm_hour; + minute = tmGMT->tm_min; + second = tmGMT->tm_sec; modifiedJulianDay = calculateMJD(year, month, day); // generate five decimal digits of modified julian date decimal digits and increment each one. diff --git a/packetsource.h b/packetsource.h index cf7a8f6..f054dc9 100644 --- a/packetsource.h +++ b/packetsource.h @@ -72,9 +72,9 @@ enum Event EVENT_P830_FORMAT_2_LABEL_3, EVENT_SUBTITLE, EVENT_DATABROADCAST, - EVENT_NUMBER_ITEMS, EVENT_SPECIAL_PAGES, - EVENT_PACKET_29 + EVENT_PACKET_29, + EVENT_NUMBER_ITEMS } ;