fix(NTPClient): NTPClient ignores second fractions #2614

This commit is contained in:
Alex Fabijanic 2022-06-21 07:28:22 +02:00
parent 6dc79c05f9
commit aa71874f2c

View File

@ -149,9 +149,10 @@ Poco::Timestamp NTPPacket::transmitTime() const
Poco::Timestamp NTPPacket::convertTime(Poco::Int64 tm) const
{
const unsigned long seventyYears = 2208988800UL;
Poco::UInt32 secsSince1900 = UInt32(Poco::ByteOrder::toLittleEndian(tm) >> 32);
unsigned long epoch = secsSince1900 - seventyYears;
return Poco::Timestamp::fromEpochTime(epoch);
Poco::UInt64 ntpTime = Poco::ByteOrder::toLittleEndian(tm);
Poco::UInt64 secs = ((ntpTime >> 32) - seventyYears) * 1000000;
Poco::UInt64 frac = ((ntpTime & 0xFFFFFFFF) * 1000000) >> 32;
return Poco::Timestamp(secs+frac);
}