diff --git a/docs/CHANGES.TXT b/docs/CHANGES.TXT index b33fafa5..33217c66 100644 --- a/docs/CHANGES.TXT +++ b/docs/CHANGES.TXT @@ -1,5 +1,6 @@ 0.96.6 (unreleased) ------------------- +- Fix: DVB EIT start time BCD decoding in XMLTV output causing invalid timestamps (#1835) - New: Add Snap packaging support with Snapcraft configuration and GitHub Actions CI workflow. - Fix: Clear status line output on Linux/WSL to prevent text artifacts (#2017) - Fix: Prevent infinite loop on truncated MKV files diff --git a/src/lib_ccx/ts_tables_epg.c b/src/lib_ccx/ts_tables_epg.c index 95747fb5..79bc5817 100644 --- a/src/lib_ccx/ts_tables_epg.c +++ b/src/lib_ccx/ts_tables_epg.c @@ -136,6 +136,7 @@ void EPG_DVB_calc_start_time(struct EPG_event *event, uint64_t time) if (mjd > 0) { long y, m, d, k; + struct tm timeinfo = {0}; // algo: ETSI EN 300 468 - ANNEX C y = (long)((mjd - 15078.2) / 365.25); @@ -145,7 +146,32 @@ void EPG_DVB_calc_start_time(struct EPG_event *event, uint64_t time) y = y + k + 1900; m = m - 1 - k * 12; - snprintf(event->start_time_string, sizeof(event->start_time_string), "%02ld%02ld%02ld%06" PRIu64 "+0000", y, m, d, time & 0xffffff); + timeinfo.tm_year = y - 1900; + timeinfo.tm_mon = m - 1; + timeinfo.tm_mday = d; + + // Decode BCD time (lower 24 bits: HHMMSS) + uint32_t bcd = (uint32_t)(time & 0xFFFFFF); + + timeinfo.tm_sec = (bcd & 0x0f) + (10 * ((bcd & 0xf0) >> 4)); + + timeinfo.tm_min = ((bcd & 0x0f00) >> 8) + (10 * ((bcd & 0xf000) >> 12)); + + timeinfo.tm_hour = ((bcd & 0x0f0000) >> 16) + (10 * ((bcd & 0xf00000) >> 20)); + + timeinfo.tm_isdst = -1; + + mktime(&timeinfo); + + snprintf(event->start_time_string, + sizeof(event->start_time_string), + "%04d%02d%02d%02d%02d%02d +0000", + timeinfo.tm_year + 1900, + timeinfo.tm_mon + 1, + timeinfo.tm_mday, + timeinfo.tm_hour, + timeinfo.tm_min, + timeinfo.tm_sec); } }