From d1358d7cc7bf7f326591f17ed097f556494865e5 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Wed, 8 Feb 2012 18:20:28 +0400 Subject: [PATCH] eitd/SIutils.cpp: add parseDVBtime function Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/87037520de6fe7c3696693686170f76a905e598e Author: [CST] Focus Date: 2012-02-08 (Wed, 08 Feb 2012) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/eitd/SIutils.cpp | 32 ++++++++++++++++++++++++++++++++ src/eitd/SIutils.hpp | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/eitd/SIutils.cpp b/src/eitd/SIutils.cpp index 42c5e6d8a..b51f29fb7 100644 --- a/src/eitd/SIutils.cpp +++ b/src/eitd/SIutils.cpp @@ -85,6 +85,8 @@ #include #include +#include "SIutils.hpp" + // Thanks to kwon time_t changeUTCtoCtime(const unsigned char *buffer, int local_time) { @@ -128,6 +130,36 @@ time_t changeUTCtoCtime(const unsigned char *buffer, int local_time) return mktime(&time) + (local_time ? -timezone : 0); } +time_t parseDVBtime(uint16_t mjd, uint32_t bcd) +{ + int year, month, day, y_, m_, k, hour, minutes, seconds; + + y_ = (int) ((mjd - 15078.2) / 365.25); + m_ = (int) ((mjd - 14956.1 - (int) (y_ * 365.25)) / 30.6001); + day = mjd - 14956 - (int) (y_ * 365.25) - (int) (m_ * 30.60001); + + hour = (bcd >> 16) & 0xFF; + minutes = (bcd >> 8) & 0xFF; + seconds = bcd & 0xFF; + + k = !!((m_ == 14) || (m_ == 15)); + + year = y_ + k + 1900; + month = m_ - 1 - k * 12; + + struct tm time; + memset(&time, 0, sizeof(struct tm)); + + time.tm_mday = day; + time.tm_mon = month - 1; + time.tm_year = year - 1900; + time.tm_hour = (hour >> 4) * 10 + (hour & 0x0f); + time.tm_min = (minutes >> 4) * 10 + (minutes & 0x0f); + time.tm_sec = (seconds >> 4) * 10 + (seconds & 0x0f); + + return mktime(&time) - timezone; +} + // Thanks to tmbinc int saveStringToXMLfile(FILE *out, const char *c, int /*withControlCodes*/) { diff --git a/src/eitd/SIutils.hpp b/src/eitd/SIutils.hpp index 917ee8c42..e4a697968 100644 --- a/src/eitd/SIutils.hpp +++ b/src/eitd/SIutils.hpp @@ -44,7 +44,10 @@ // Alles neu macht der Mai. // // +#include + time_t changeUTCtoCtime(const unsigned char *buffer, int local_time=1); +time_t parseDVBtime(uint16_t mjd, uint32_t bcd); // returns the descriptor type as readable text const char *decode_descr (unsigned char tag_value);