//
//  main.cpp
//  cpp1027time
//
//  Created by Minho Shin on 10/26/14.
//  Copyright (c) 2014 Minho Shin. All rights reserved.
//

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

// class Time
// Goal: manage time with hour, min, seconds
// funtion: perform plus, minus, comparison....

class Time {
    
protected: //1027
    // private member variable (Data)
    int h;	// 0~23
    int m;	// 0~59
    int s;	// 0~59
    
    // public member function
public:
    // Constructor
    Time() { h=m=s=0; }
    Time( int hour, int min, int sec ) { h=hour; m=min; s=sec; }
    
    // accessor (getter)
    int getHour() { return h; }
    int getMin() { return m; }
    int getSec() { return s; }
    
    // accessor (setter)
    void setHour( int hour ) { if( 0 <= hour && hour <= 23 ) h = hour; }
    void setMin( int min ) { if( 0 <= min && min <= 59 ) m = min; }
    void setSec( int sec ) { if( 0 <= sec && sec <= 59 ) s = sec; }
    
    //1027
    void set( int h, int m, int s) { setHour(h); setMin(m); setSec(s); }
    
    friend Time operator+( Time t1, Time t2 );
    
};


class TimeZ : public Time
{
public:
    enum Zone {EST, KST};
    TimeZ() : zone(KST) {} // Time() is called, set 0, 0, 0
    TimeZ( int hour, int min, int sec ) : Time(hour, min, sec), zone(KST) {}
    TimeZ( int hour, int min, int sec, Zone z ) : Time(hour, min, sec), zone(z) {}
    //TimeZ( Time t ) : Time(t), zone(KST) {}
    void set(int hour, int min, int sec, Zone z) { Time::set(hour, min, sec); zone = z; }
    void setZone( Zone z );
    string zoneString( Zone z ) { return (z == KST) ? "KST" : "EST"; }
    void addHour( int hour ) { h = ( h + hour ) % 24; }
    void operator=(Time t) { h=t.getHour(); m=t.getMin(); s=t.getSec(); zone=KST; }
    string toString();
    
    friend TimeZ operator+( TimeZ t1, TimeZ t2 );
    friend ostream &operator<<( ostream &out, TimeZ &t);
    
private:
    Zone zone;
};

Time operator+( Time t1, Time t2 ) {
    Time t;
    t.h = t1.h + t2.h;
    t.m = t1.m + t2.m;
    t.s = t1.s + t2.s;
    return t;
}

string TimeZ::toString()
{
    stringstream str;
    str << h << ":" << m << ":" << s << " " << zoneString(zone);
    return str.str();
}

void TimeZ::setZone(Zone z)
{
    if( z == zone ) return;
    
    if( zone == EST && z == KST ) addHour( 13 );
    
    if( zone == KST && z == EST ) addHour( -13 );
    
    zone = z;
}

TimeZ operator+( TimeZ t1, TimeZ t2 ) {
    t2.setZone(t1.zone);
    cout << "now:" << t2 << endl;
    
    t1.setHour(t1.h+t2.h);
    t1.setMin(t1.m+t2.m);
    t1.setSec(t1.s+t2.s);
    
    return t1;
}

ostream &operator<<( ostream &out, TimeZ &t)
{
    out << t.toString();
    return out;
}

int main() {
    TimeZ t1(10, 0, 0);
    TimeZ t2(14, 0, 0, TimeZ::EST);
    
    cout << t1 << endl;
    cout << t2 << endl;

    TimeZ t3 = t1 + t2;
    
    
    cout << t3.toString() << endl;
    
    cout << "t3 is " << t3.getHour() << " hour, " << t3.getMin() << "min, " << t3.getSec() << "sec." << endl;
    system( "read" );
}

