// time.cc P. Conrad CISC181 Spring 2005

#include "time.h"
#include <iostream>
#include <iomanip> // for setfill and setw
using namespace std;

const Time_C Time_C::operator +(const Duration_C & right)
{
  int newMinute = (this->min + right.getMin() ) % 60;
  int newHour = this->hour + right.getHour() + (this->min + right.getMin())/60;
  newHour = newHour % 24;

  // This constructs a new Time_C value and returns it as the return value
  return Time_C ( newHour, newMinute);
}
  
void Time_C::print() const
{ 
  // Print the hour. Use mod 12 to convert pm times. Print 12 instead of 0  
  cout <<  ( ( hour%12==0 ) ? 12 : (hour%12) ); 
  // print ":" then the minute, zero filled in width of two.
  cout << ":" << setfill('0') << setw(2) << min << setfill(' '); 
  // print either am or pm  Noon prints as 12:00pm
  cout << ( (hour<12) ? "am" : "pm" ); 
}
	
