01: #include <iostream>
02: #include <iomanip>
04: using namespace std;
05: 
06: #include "ccc_time.h"
08: /**
09:    Compute the number of seconds between two points in time.
10:    @param a a point in time
11:    @param b another point in time
12:    @return the number of seconds that a is away from b
13: */
14: int operator-(Time a, Time b)
15: {  return a.seconds_from(b);  }
18: 
19: /**
20:    Compute a point in time that is some number of seconds away.
21:    @param a a point in time
22:    @param sec the seconds to add
23:    @return a point in time that is sec seconds away from a
24: */
25: Time operator+(Time a, int sec)
26: {  Time r = a;
28:    r.add_seconds(sec);
29:    return r;
30: }
31: 
32: /**
33:    Compare two points in time.
34:    @param a a point in time
35:    @param b another point in time
36:    @return true if they are the same
37: */
38: bool operator==(Time a, Time b)
39: {  return a.seconds_from(b) == 0;  }
42: 
43: /**
44:    Compare two points in time.
45:    @param a a point in time
46:    @param b another point in time
47:    @return true if they are the different
48: */
49: bool operator!=(Time a, Time b)
50: {  return a.seconds_from(b) != 0;   }
53: 
54: /**
55:    Print a Time object
56:    @param out an output stream
57:    @param a a point in time
58:    @return out
59: */
60: ostream& operator<<(ostream& out, Time a)
61: {  out << a.get_hours() << ":"
63:        << setw(2) << setfill('0') 
64:        << a.get_minutes() << ":"
65:        << setw(2) << a.get_seconds() << setfill(' ');
66:    return out;
67: } 
68: 
69: int main()
70: {  Time now;
72:    cout << "Now it is " << now << "\n";
73:    Time later = now + 1000;
74:    cout << "A thousand seconds later it is " << later << "\n";
75:    Time now2;
76:    if (now == now2) cout << "It still is " << now2 << "\n";
78:    if (now != now2) cout << "It is already " << now2 << "\n";
80:    cout << "Another " << later - now2 
81:         << " seconds until " << later << "\n";
82:    return 0;
83: }
84: