Commit c23215ea authored by Cédric Traizet's avatar Cédric Traizet
Browse files

TEST: add unit test for TimePoint::GetJulianDay and TimePoint::GetModifiedJulianDay

parent e5c016b9
......@@ -62,12 +62,14 @@ std::istream & TimePoint::Read(std::istream & is, const std::string & format)
double TimePoint::GetJulianDay() const
{
return (m_Time.time_since_epoch().count() * details::internalPeriod) / 86400.0 + 2440587.5;
// 86400 is the number of seconds in a day, 2440587.5 is the offset in days between the UnixTime origin and the Julian day origin
return (m_Time.time_since_epoch().count() * details::internalPeriod / 86400.0 + 2440587.5);
}
double TimePoint::GetModifiedJulianDay() const
{
return (m_Time.time_since_epoch().count() * details::internalPeriod) / 86400.0 + 40587;
// 86400 is the number of seconds in a day, 40587 is the offset in days between the UnixTime origin and the modified Julian day origin
return (m_Time.time_since_epoch().count() * details::internalPeriod / 86400.0 + 40587);
}
date::year_month_day ToYMD(details::InternalTimePointType in)
......
......@@ -86,6 +86,11 @@ BOOST_AUTO_TEST_CASE(TimePoint)
BOOST_REQUIRE_THROW(otb::MetaData::ReadFormattedDate("2021-6-21 00:1:4.42578987"),
otb::MissingMetadataException);
// Julian day and Modified julian day
auto mjdOrigin = otb::MetaData::ReadFormattedDate("1858-11-17T00:00:00");
BOOST_TEST(mjdOrigin.GetJulianDay() == 2400000.5);
BOOST_TEST(mjdOrigin.GetModifiedJulianDay() == 0.);
}
BOOST_AUTO_TEST_CASE(TimePointPrecision)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment