// time.cc  P. Conrad for CISC220, 06J

#include "time.h"

#include <iomanip> // for setw() and setfill()

Time_C::Time_C (int theHour, int theMinute) 
{ 
  if (theHour > 23 || 
      theHour < 0 || 
      theMinute > 59 ||
      theMinute < 0 )
    {
      hour = minute = -1;
    }
  else
    {
      hour = theHour; minute = theMinute;
    }
}

void Time_C::print(std::ostream &out) const
{
  if (badTime())
    out << "xx:xx";
  else
    {
      // Note: std::setfill(0) will not work; it expect a char argument
      // However, std::setfill(0) WILL compile, which can be misleading...
      // C and C++ treat characters and integers as interchangable...
      // But setfill(0) just fills with "null characters"

      out <<  std::setfill('0')  << std::setw(2) << hour
	  << ":" 
	  << std::setfill('0') << std::setw(2) << minute;
    }
}

std::ostream & operator << (std::ostream & right, 
			    const Time_C &left)
{
  left.print(right);
  return right;
}

