-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcDate_t.h
More file actions
98 lines (71 loc) · 2.28 KB
/
cDate_t.h
File metadata and controls
98 lines (71 loc) · 2.28 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// cDate_t.h
//
// assumption from HW & VirtualTau Forum:
// ***********************************
// 1. accumulate the day/month if exceeding 7/12
// 2. CTOR gets only valid values
// 3. year > 1900
// 4. day of the week can be calculate only to value after 1/1/1970
//
#ifndef CDATE_T_H_
#define CDATE_T_H_
#include <string>
#include <sstream>
using namespace std;
class cDate_t {
public:
static int format; //Format of printing
cDate_t(); //default CTOR from current date
cDate_t(int day, int month, int year); //CTOR from day, month and year
cDate_t(const cDate_t& d); //copy CTOR
~cDate_t(); //DTOR
const cDate_t& operator=(const cDate_t& d); //assignment operator overload
void setDate(int day, int month, int year); //set a new date
void printDate() const; //print the date in the current default format
void printDate(int format) const; //print the date & set the default format:
//dd:2, mon:3, year:4 - 22/Jan/2001
//dd:2, mon:2, year:4 - 22/01/2001
//dd:2, mon:2, year:4 - 22/Jan/2001
int getDay()const; //retrieve the day
int getMonth()const; //retrieve the month
int getYear()const; //retrieve the year
int getDayOfTheYear(); //retrieve the day of the year(1-365)
bool isYearLeap()const; //Is year leap or not (return true iff ((year % 4) == 0))
string getNameOfDay(); //retrieve the name of the day
string getNameOfMonth() const; //retrieve the name of the month
private:
int day;
int month;
int year;
struct tm* time_info;
static const int daysInMonth[]; //Number of days in standard (non-Leap) Year
static const string cDate_t::dayNames[];
static const string cDate_t::months[];
void setDate_p( int d, int m, int y );
void setTime_info();
};
/********************
* Inline functions
********************/
/********************
* Getters
********************/
inline int cDate_t::getDay() const{
return this->day;
}
inline int cDate_t::getMonth() const{
return this->month;
}
inline int cDate_t::getYear() const{
return this->year;
}
inline string cDate_t::getNameOfMonth() const
{
return months[month-1];
}
inline bool cDate_t::isYearLeap() const
{
return ((year % 4) == 0);
}
#endif