-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDateTime
More file actions
198 lines (197 loc) · 7.82 KB
/
Copy pathDateTime
File metadata and controls
198 lines (197 loc) · 7.82 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* -*- c++ -*- */
///////////////////////////////////////////
// DateTime
// -------------------------------------
// file : DateTime
// author : Ben Kietzman
// begin : 2010-03-03
// copyright : Ben Kietzman
// email : ben@kietzman.org
///////////////////////////////////////////
/*! \file DateTime
* \brief DateTime Class
*/
#ifndef _COMMON_DATETIME_
#define _COMMON_DATETIME_
// {{{ includes
#include <ctime>
#include <cstring>
#include <string>
using namespace std;
// }}}
extern "C++"
{
namespace common
{
// {{{ DateTime
//! Performs date/time retrieval and manipulation.
class DateTime
{
public:
DateTime();
~DateTime();
//! Gets the current year.
inline int getYear(int &nValue){struct tm tTime; time_t CTime; time(&CTime); localtime_r(&CTime, &tTime); return nValue = (tTime.tm_year + 1900);};
//! Gets the current month.
inline int getMonth(int &nValue){struct tm tTime; time_t CTime; time(&CTime); localtime_r(&CTime, &tTime); return nValue = (tTime.tm_mon + 1);};
//! Gets the current day.
inline int getDay(int &nValue){struct tm tTime; time_t CTime; time(&CTime); localtime_r(&CTime, &tTime); return nValue = tTime.tm_mday;};
//! Gets the current hour.
inline int getHour(int &nValue){struct tm tTime; time_t CTime; time(&CTime); localtime_r(&CTime, &tTime); return nValue = tTime.tm_hour;};
//! Gets the current minute.
inline int getMinute(int &nValue){struct tm tTime; time_t CTime; time(&CTime); localtime_r(&CTime, &tTime); return nValue = tTime.tm_min;};
//! Gets the current second.
inline int getSecond(int &nValue){struct tm tTime; time_t CTime; time(&CTime); localtime_r(&CTime, &tTime); return nValue = tTime.tm_sec;};
//! Converts civilian time to military.
/*!
* \param nHour - The given civilian hour. Returns the corresponding military hour.
* \param strTimeOfDay - The time-of-day as "AM" or "PM".
*/
void civilianToMilitary(int &nHour, const string strTimeOfDay);
//! Converts military time to civilian.
/*!
* \param nHour - The given military hour. Returns the corresponding civilian hour.
* \param strTimeOfDay - Returns the time-of-day as "AM" or "PM".
*/
void militaryToCivilian(int &nHour, string &strTimeOfDay);
//! Determines if it is leap year.
/*!
* \param nYear - The given year.
*/
bool isLeapYear(const int nYear);
//! Performs year addition.
/*!
* \param nYear - The given year.
* \param nNumber - The number to be added.
*/
void addYears(int &nYear, const int nNumber);
//! Performs month addition.
/*!
* Accounts for rollover in date figures of higher precedence.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nNumber - The number to be added.
*/
void addMonths(int &nYear, int &nMonth, const int nNumber);
//! Performs day addition.
/*!
* Accounts for rollover in date figures of higher precedence.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nDay - The given day.
* \param nNumber - The number to be added.
*/
void addDays(int &nYear, int &nMonth, int &nDay, const int nNumber);
//! Performs civilian hour addition.
/*!
* Accounts for rollover in date figures of higher precedence.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nDay - The given day.
* \param nHour - The given civilian hour.
* \param strTimeOfDay - The given time-of-day as "AM" or "PM".
* \param nNumber - The number to be added.
*/
void addHoursCivilian(int &nYear, int &nMonth, int &nDay, int &nHour, string &strTimeOfDay, const int nNumber);
//! Performs military hour addition.
/*!
* Accounts for rollover in date figures of higher precedence.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nDay - The given day.
* \param nHour - The given military hour.
* \param nNumber - The number to be added.
*/
void addHoursMilitary(int &nYear, int &nMonth, int &nDay, int &nHour, const int nNumber);
//! Performs civilian minute addition.
/*!
* Accounts for rollover in date figures of higher precedence.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nDay - The given day.
* \param nHour - The given civilian hour.
* \param nMinute - The given minute.
* \param strTimeOfDay - The given time-of-day as "AM" or "PM".
* \param nNumber - The number to be added.
*/
void addMinutesCivilian(int &nYear, int &nMonth, int &nDay, int &nHour, int &nMinute, string &strTimeOfDay, const int nNumber);
//! Performs military minute addition.
/*!
* Accounts for rollover in date figures of higher precedence.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nDay - The given day.
* \param nHour - The given military hour.
* \param nMinute - The given minute.
* \param nNumber - The number to be added.
*/
void addMinutesMilitary(int &nYear, int &nMonth, int &nDay, int &nHour, int &nMinute, const int nNumber);
//! Performs civilian second addition.
/*!
* Accounts for rollover in date figures of higher precedence.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nDay - The given day.
* \param nHour - The given civilian hour.
* \param nMinute - The given minute.
* \param nSecond - The given Second.
* \param strTimeOfDay - The given time-of-day as "AM" or "PM".
* \param nNumber - The number to be added.
*/
void addSecondsCivilian(int &nYear, int &nMonth, int &nDay, int &nHour, int &nMinute, int &nSecond, string &strTimeOfDay, const int nNumber);
//! Performs military second addition.
/*!
* Accounts for rollover in date figures of higher precedence.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nDay - The given day.
* \param nHour - The given military hour.
* \param nMinute - The given minute.
* \param nSecond - The given second.
* \param nNumber - The number to be added.
*/
void addSecondsMilitary(int &nYear, int &nMonth, int &nDay, int &nHour, int &nMinute, int &nSecond, const int nNumber);
//! Get the number of days in the current year.
/*!
* Accounts for leap year.
* \param nDaysInYear - The result.
* \return The result.
*/
int daysInYear(int &nDaysInYear);
//! Get the number of days in the given year.
/*!
* Accounts for leap year.
* \param nYear - The given year.
* \param nDaysInYear - The result.
* \return The result.
*/
int daysInYear(const int nYear, int &nDaysInYear);
//! Get the number of days in the current month.
/*!
* Accounts for leap year.
* \param nDaysInMonth - The result.
* \return The result.
*/
int daysInMonth(int &nDaysInMonth);
//! Get the number of days in the given month of the current year.
/*!
* Accounts for leap year.
* \param nMonth - The given month.
* \param nDaysInMonth - The result.
* \return The result.
*/
int daysInMonth(const int nMonth, int &nDaysInMonth);
//! Get the number of days in the given month of the given year.
/*!
* Accounts for leap year.
* \param nYear - The given year.
* \param nMonth - The given month.
* \param nDaysInMonth - The result.
* \return The result.
*/
int daysInMonth(const int nYear, const int nMonth, int &nDaysInMonth);
};
// }}}
}
}
#endif