// timesec.cpp
// Version 3
// Glenn G. Chappell
// 14 Sep 2009
//
// For CS 311 Fall 2009
// Source for class TimeSec

#include "timesec.h"
#include <iostream>  // for std::ostream

// NOTE:
//     Pre- & postconditions for functions defined in this file
//      are found in timesec.h.


// ************************************************************************
// class TimeSec - Definitions of Member Functions
// ************************************************************************


// setTime
void TimeSec::setTime(int hh,
                      int mm,
                      int ss)
{ secs_ = hh*60*60 + mm*60 + ss; }

// getTime
void TimeSec::getTime(int & hh,
                      int & mm,
                      int & ss) const
{
    ss = secs_ % 60;
    mm = (secs_/60) % 60;
    hh = secs_/(60*60);
}


// ************************************************************************
// class TimeSec - Definitions of Associated Global Operators
// ************************************************************************


// op== (TimeSec, TimeSec)
// Friend of class TimeSec
bool operator==(const TimeSec & a,
                const TimeSec & b)
{ return a.secs_ == b.secs_; }

// op!= (TimeSec, TimeSec)
bool operator!=(const TimeSec & a,
                const TimeSec & b)
{ return !(a==b); }

// op<< (stream insertion for TimeSec)
std::ostream & operator<<(std::ostream & theStream,
                          const TimeSec & printMe)
{
    int hh, mm, ss;
    printMe.getTime(hh, mm, ss);
    if (hh < 10)
        theStream << " ";
    theStream << hh << ":";
    if (mm < 10)
        theStream << "0";
    theStream << mm << ":";
    if (ss < 10)
        theStream << "0";
    theStream << ss;
    return theStream;
}

