Skip to content

Commit

Permalink
Re #6270. Improve precision of run_start/end workspace log values.
Browse files Browse the repository at this point in the history
Previously the precision of these would be the nearest second as
the setting went via the DateAndTime::toISO8601String() method,
which truncated the time even if it had a better precision than
that (as the SNS files do). This then caused some oddities when
viewing logs because they do preserve the incoming precision.

DateAndTime::toISO8601String() now preserves the nanosecond precision
of the underlying DateAndTime class.
(cherry picked from commit 0a2679c)
  • Loading branch information
RussellTaylor authored and Michael Reuter committed Dec 10, 2012
1 parent fd94f48 commit 830f6b8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Algorithms/test/FilterByTime2Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class FilterByTime2Test : public CxxTest::TestSuite
outputWS = "eventWS_relative";
TS_ASSERT_THROWS_NOTHING(alg->setPropertyValue("OutputWorkspace", outputWS));
//Get 1 minute worth
TS_ASSERT_THROWS_NOTHING(alg->setPropertyValue("StartTime", "60.46"));
TS_ASSERT_THROWS_NOTHING(alg->setPropertyValue("StopTime", "120.46"));
TS_ASSERT_THROWS_NOTHING(alg->setPropertyValue("StartTime", "60"));
TS_ASSERT_THROWS_NOTHING(alg->setPropertyValue("StopTime", "120"));

alg->execute();
TS_ASSERT( alg->isExecuted() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class LoadEventPreNexus2Test : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( p = outputWS->mutableRun().getProperty("run_start"); )
if (p)
{
TS_ASSERT_EQUALS( p->value(), "2010-03-25T16:08:37") ;
TS_ASSERT_EQUALS( p->value(), "2010-03-25T16:08:37.457381666") ;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class LoadEventPreNexusTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( p = outputWS->mutableRun().getProperty("run_start"); )
if (p)
{
TS_ASSERT_EQUALS( p->value(), "2010-03-25T16:08:37") ;
TS_ASSERT_EQUALS( p->value(), "2010-03-25T16:08:37.457381666") ;
}
}

Expand Down
16 changes: 3 additions & 13 deletions Code/Mantid/Framework/Kernel/src/DateAndTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,24 +535,14 @@ std::string DateAndTime::toFormattedString(const std::string format) const
}

//------------------------------------------------------------------------------------------------
/** Return the date and time as an ISO8601-formatted string without fractional seconds.
* @return string
/** Return the date and time as an ISO8601-formatted string
* @return The ISO8601 string
*/
std::string DateAndTime::toISO8601String() const
{
return this->toFormattedString("%Y-%m-%dT%H:%M:%S");
return boost::posix_time::to_iso_extended_string(to_ptime());
}


////------------------------------------------------------------------------------------------------
///** Stream operator
// */
//std::ostream& DateAndTime::operator<< (std::ostream& stream, const DateAndTime & obj)
//{
// stream << obj->toSimpleString();
// return stream;
//}

//------------------------------------------------------------------------------------------------
/** Get the year of this date.
* @return the year
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Kernel/test/DateAndTimeTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class DateAndTimeTest: public CxxTest::TestSuite
TS_ASSERT_EQUALS( s.substr(0,20), "1990-Jan-02 03:04:05");
TS_ASSERT_EQUALS( a.toFormattedString(), "1990-Jan-02 03:04:05");
TS_ASSERT_EQUALS( a.toFormattedString("%Y-%m-%d"), "1990-01-02");
TS_ASSERT_EQUALS( a.toISO8601String(), "1990-01-02T03:04:05");
TS_ASSERT_EQUALS( a.toISO8601String(), "1990-01-02T03:04:05.678000000");
}

void test_to_int64()
Expand Down

0 comments on commit 830f6b8

Please sign in to comment.