Ticket #2104 (closed: fixed)

Opened 10 years ago

Last modified 5 years ago

DateAndTime class needs friend function

Reported by: Peter Peterson Owned by: Janik Zikovsky
Priority: major Milestone: Iteration 27
Component: Mantid Keywords:
Cc: Blocked By:
Blocking: Tester: Nick Draper

Description

To allow for easier simple debugging (i.e. print statements), DateAndTime should have a friend method for std::ostream that prints to_ISO8601_string(). The function declaration should be something like:

friend ostream & operator<<( ostream & os, const DateAndTime obj);

Change History

comment:1 Changed 10 years ago by Janik Zikovsky

  • Status changed from new to accepted

comment:2 Changed 10 years ago by Janik Zikovsky

It already has an << operator that prints a simple string - is that good enough?

  void test_stream_operator()
  {
    DateAndTime a;
    std::ostringstream message;
    a = DateAndTime("1990-01-02 03:04:05.678");
    message << a;
    TS_ASSERT_EQUALS( message.str(), a.to_simple_string() );
  }

comment:3 Changed 10 years ago by Janik Zikovsky

P.S. example above prints 1990-Jan-02 03:04:05.678000000

comment:4 Changed 10 years ago by Peter Peterson

I missed that at the end of the file.

It needs to be declared a friend so it can be called from anywhere.

comment:5 Changed 10 years ago by Janik Zikovsky

  • Status changed from accepted to verify
  • Resolution set to fixed

Fixed in revision [8220]

comment:6 Changed 10 years ago by Nick Draper

  • Status changed from verify to verifying
  • Tester set to Nick Draper

comment:7 Changed 10 years ago by Nick Draper

  • Status changed from verifying to closed

comment:8 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 2951

Note: See TracTickets for help on using tickets.