174 | | // TODO: clean this up some since its sort of a mess right now |
175 | | // Original function taken from dvbdate.c in linuxtv-apps code |
176 | | |
177 | | // Use the routine specified in ETSI EN 300 468 V1.4.1, |
178 | | // "Specification for Service Information in Digital Video Broadcasting" |
179 | | // to convert from Modified Julian Date to Year, Month, Day. |
180 | | |
181 | | const float tmpA = 1.0 / 365.25; |
182 | | const float tmpB = 1.0 / 30.6001; |
183 | | |
184 | | float mjd = (buf[0] << 8) | buf[1]; |
185 | | int year = (int) truncf((mjd - 15078.2f) * tmpA); |
186 | | int month = (int) truncf( |
187 | | (mjd - 14956.1f - truncf(year * 365.25f)) * tmpB); |
188 | | int day = (int) truncf( |
189 | | (mjd - 14956.0f - truncf(year * 365.25f) - truncf(month * 30.6001f))); |
190 | | int i = (month == 14 || month == 15) ? 1 : 0; |
191 | | |
192 | | QDate date(1900 + year + i, month - 1 - i * 12, day); |
193 | | QTime time(byteBCD2int(buf[2]), byteBCD2int(buf[3]), |
194 | | byteBCD2int(buf[4])); |
195 | | |
196 | | return QDateTime(date, time); |
| 174 | QDateTime result; |
| 175 | // Modified Julian date as number of days since 17th November 1858. |
| 176 | // 1st Jan 1970 was date 40587. |
| 177 | uint mjd = (buf[0] << 8) | buf[1]; |
| 178 | uint secsSince1970 = (mjd - 40587) * (24 * 60 * 60); |
| 179 | secsSince1970 += (buf[2] * 60 + buf[3]) * 60 + buf[4]; |
| 180 | result.setTime_t(secsSince1970); |
| 181 | return result; |