3394ff7785eadd195ed0971521c855540d40bcce
[AXE.git] / src / hour.cpp
1 /**************************************************************************
2 **  (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : hour.cpp
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.1 $
9 **
10 **  DESCRIPTION      :  
11 **
12 **  EXPORTED OBJECTS : 
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Feb 06, 1998
20 **      LAST UPDATE     : Oct 16, 1999
21 **************************************************************************/
22
23 /*****************************
24    $Log: hour.cpp,v $
25    Revision 1.1  2002-07-25 08:01:27  arjen
26    First checkin, AXE release 0.2
27
28 *****************************/
29
30 static const char *RCSID = "$Id: hour.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
31
32 #include "date.h"
33 #include "parsedate.h"
34
35 hour::hour(String s)
36 {
37    struct parseddate *pd;
38
39    pd = parsedate(s);
40    hours = pd->hour;
41    minutes = pd->minute;
42    seconds = pd->second;
43 }
44
45 hour operator+(hour &t1, hour &t2)
46 {
47    hour t = t1;
48
49    t.seconds += t2.seconds;
50    if (t.seconds >= 60)
51    {
52       t.minutes++;
53       t.seconds -= 60;
54    }
55    t.minutes += t2.minutes;
56    if (t.minutes >= 60)
57    {
58       t.hours++;
59       t.minutes -= 60;
60    }
61    t.hours += t2.hours;
62
63    return t;
64 }
65
66 hour hour::operator+=(hour t)
67 {
68    seconds += t.seconds;
69    if (seconds >= 60)
70    {
71       minutes++;
72       seconds -= 60;
73    }
74    minutes += t.minutes;
75    if (minutes >= 60)
76    {
77       hours++;
78       minutes -= 60;
79    }
80    hours += t.hours;
81
82    return *this;
83 }
84
85 hour operator-(hour &t1, hour &t2)
86 {
87    hour t = t1;
88
89    t.seconds -= t2.seconds;
90    if (t.seconds < 0)
91    {
92       t.minutes--;
93       t.seconds += 60;
94    }
95
96    t.minutes -= t2.minutes;
97    if (t.minutes < 0)
98    {
99       t.hours--;
100       t.minutes += 60;
101    }
102
103    t.hours -= t2.hours;
104
105    return t;
106 }
107
108 ostream& operator<<(ostream &s, const hour &t)
109 {
110    s << t.hours << ":" << t.minutes << ":" << t.seconds;
111
112    return s;
113 }
114