bool ossimPredatorKlvTable::getDateUsingEpoc(ossimDate& d)const { bool result = false; ossim_int64 t; ossim_float64 fraction=0; if(getUnixEpocTimestampInSeconds(t, fraction)) { result = true; d.setTimeNoAdjustmentGivenEpoc(t); d.setFractionalSecond(fraction); } return result; }
bool ossimPredatorKlvTable::getDateUsingUtc(ossimDate& d, bool shiftToGmtZero)const { bool result = false; ossimString utc = getUtcTimestamp(); if(utc.size() > 0) { result = d.setIso8601(utc, shiftToGmtZero); } return result; }
static void convertOssimToFileTime(FILETIME *ft, const ossimDate& dt) { SYSTEMTIME st; st.wDay = dt.getDay(); st.wMonth = (WORD)(dt.getMonth()); st.wYear = (WORD)dt.getYear(); st.wHour = dt.getHour(); st.wMinute = dt.getMin(); st.wSecond = dt.getSec(); // st.wMilliseconds = dt.GetMillisecond(); FILETIME ftLocal; if ( !::SystemTimeToFileTime(&st, &ftLocal) ) { // wxLogLastError(_T("SystemTimeToFileTime")); } if ( !::LocalFileTimeToFileTime(&ftLocal, ft) ) { // wxLogLastError(_T("LocalFileTimeToFileTime")); } }
void check_time(char const* format, char const* sDate, int year, int month, int day, int hour, int min, int sec, double fsec) { // std::cout << "Test " << sDate << " against " << format << std::endl; const ossimDate d = ossimplugins::time::details::strptime(format, sDate); BOOST_CHECK_EQUAL(d.getYear(), year); BOOST_CHECK_EQUAL(d.getMonth(), month); BOOST_CHECK_EQUAL(d.getDay(), day); BOOST_CHECK_EQUAL(d.getHour(), hour); BOOST_CHECK_EQUAL(d.getMin(), min); BOOST_CHECK_EQUAL(d.getSec(), sec); BOOST_CHECK_EQUAL(d.getFractionalSecond(), fsec); // Reference ossimLocalTm iso; iso.setIso8601(sDate); BOOST_CHECK_EQUAL(d.getModifiedJulian(), iso.getModifiedJulian()); // Is ossimDate |--> MJD bijective ? const double dMJD = d.getModifiedJulian(); ossimDate d2; d2.setDateFromModifiedJulian(dMJD); BOOST_CHECK_EQUAL(d2.getYear(), year); BOOST_CHECK_EQUAL(d2.getMonth(), month); BOOST_CHECK_EQUAL(d2.getDay(), day); BOOST_CHECK_EQUAL(d2.getHour(), hour); BOOST_CHECK_EQUAL(d2.getMin(), min); BOOST_CHECK_CLOSE_FRACTION(d2.getSec()+d2.getFractionalSecond(), sec+fsec, 1e-6); // Alternative implementation BOOST_CHECK_CLOSE_FRACTION(d.getModifiedJulian(), getModifiedJulianDate(sDate), 1e-12); // Check string conversion // Yes, this is likelly to fail du to double imprecisions // - official ossimDate string conversion ossimplugins::time::ModifiedJulianDate mjd = ossimplugins::time::toModifiedJulianDate(sDate); // std::cout << "MJD("<<sDate<<"): " << mjd.as_day_frac() << std::endl; BOOST_CHECK_CLOSE_FRACTION(d.getModifiedJulian(), mjd.as_day_frac(), 1e-12); std::ostringstream oss; oss << d.getYear() << '-' << std::setw(2) << std::setfill('0') << d.getMonth() << '-' << d.getDay() << 'T'; d.printTime(oss); if (d.getFractionalSecond() > 0) { oss << '.' << std::setw(6) << (d.getFractionalSecond() * 1000*1000); } BOOST_CHECK_EQUAL(oss.str(), sDate); // - our string conversion // std::cout << std::setprecision(20) ; // std::cout << mjd.as_day_frac() << " -> " << to_simple_string(mjd) << " / " << d.getModifiedJulian() << "\n"; // std::cout << oss.str() << "\n"; // We know this test will fail because of float rounding => just display std::cout.precision(16); std::cout << mjd << " as a simple string (" << ossimplugins::time::to_simple_string(mjd) << ") is expected to differ from " << sDate << "\n"; // BOOST_CHECK_EQUAL(to_simple_string(mjd), sDate); }
ossimplugins::time::ModifiedJulianDate ossimplugins::time::toModifiedJulianDate(string_view const& utcTimeString) { const ossimDate date = details::strptime("%Y-%m-%dT%H:%M:%S%.", utcTimeString); return ModifiedJulianDate(date.getModifiedJulian()); }