Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bugfix/8351_ipython_datetime_error'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici committed Nov 12, 2013
2 parents 0362116 + e96a664 commit 72a3f99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ using Mantid::Kernel::DateAndTime;
using Mantid::Kernel::time_duration;
using namespace boost::python;

/** Circumvent a bug in IPython 1.1, which chokes on nanosecond precision datetimes.
* Adding a space to the string returned by the C++ method avoids it being given
* the special treatment that leads to the problem.
*/
std::string ISO8601StringPlusSpace(DateAndTime & self)
{
return self.toISO8601String()+" ";
}

void export_DateAndTime()
{
class_<DateAndTime>("DateAndTime", no_init)
Expand All @@ -17,7 +26,7 @@ void export_DateAndTime()
.def("total_nanoseconds", &DateAndTime::totalNanoseconds)
.def("totalNanoseconds", &DateAndTime::totalNanoseconds)
.def("setToMinimum", &DateAndTime::setToMinimum)
.def("__str__", &Mantid::Kernel::DateAndTime::toISO8601String)
.def("__str__", &ISO8601StringPlusSpace)
// cppcheck-suppress duplicateExpression
.def(self == self)
// cppcheck-suppress duplicateExpression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_startime(self):

runstart = run.startTime()
runstartstr = str(runstart)
self.assertEquals(runstartstr, "2008-12-18T17:58:38")
self.assertEquals(runstartstr, "2008-12-18T17:58:38 ") # The space at the end is to get around an IPython bug (#8351)
self.assertTrue(isinstance(runstart, DateAndTime))

def test_endtime(self):
Expand All @@ -101,7 +101,7 @@ def test_endtime(self):

runend = run.endTime()
runendstr = str(runend)
self.assertEquals(runendstr, "2008-12-18T17:59:40")
self.assertEquals(runendstr, "2008-12-18T17:59:40 ") # The space at the end is to get around an IPython bug (#8351)
self.assertTrue(isinstance(runend, DateAndTime))

if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
class DateAndTimeTest(unittest.TestCase):

iso_str = "2008-12-18T17:58:38"
# We had to add a space to the end of the string representation to get around an IPython bug (#8351)
iso_str_plus_space = iso_str + " "

def test_construction_with_ISO_string_produces_expected_object(self):
dt = DateAndTime(self.iso_str)
self.assertEquals(self.iso_str, str(dt))
self.assertEquals(self.iso_str_plus_space, str(dt))
self.assertEquals(dt.totalNanoseconds(), 598471118000000000)

def test_construction_with_total_nano_seconds(self):
dt = DateAndTime(598471118000000000)
self.assertEquals(self.iso_str, str(dt))
self.assertEquals(self.iso_str_plus_space, str(dt))

if __name__ == "__main__":
unittest.main()
unittest.main()

0 comments on commit 72a3f99

Please sign in to comment.