-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcDateTime_t.cpp
More file actions
78 lines (48 loc) · 1.21 KB
/
cDateTime_t.cpp
File metadata and controls
78 lines (48 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "cDateTime_t.h"
#include "cTime_t.h"
#include "cDate_t.h"
#include <iostream>
using namespace std;
/*****************
* CTORs & DTOR
*****************/
cDateTime_t::cDateTime_t(){
}
cDateTime_t::cDateTime_t(int day, int month, int year, int hour, int minute, int second){
time_p.setTime(hour, minute, second);
date_p.setDate(day, month, year);
}
cDateTime_t::cDateTime_t(const cTime_t &t, const cDate_t &d){
time_p = t;
date_p = d;
}
cDateTime_t::cDateTime_t(const cDateTime_t &t): time_p(t.time_p), date_p(t.date_p){
}
cDateTime_t::~cDateTime_t(){
}
/*********************
* Operators
********************/
const cDateTime_t &cDateTime_t::operator+(const cTime_t &t){
//If time addition overflows 24 hours --> add 1 date to date_p
if (time_p.getHours() + t.getHours() >= 24){
date_p.setDate(date_p.getDay() + 1, date_p.getMonth(), date_p.getYear());
}
time_p = time_p + t;
return *this;
}
const cDateTime_t &cDateTime_t::operator=(const cDateTime_t &t){
if (this != &t){
time_p = t.time_p;
date_p = t.date_p;
}
return *this;
}
/*******************
* Public methods
******************/
void cDateTime_t::print() const{
date_p.printDate();
cout << ' ';
time_p.printTime();
}