CTR Pia  4.11.3
Game Communication Engine
common_DateTime.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: common_DateTime.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/common/common_definitions.h>
18 
19 namespace nn
20 {
21 namespace pia
22 {
23 namespace common
24 {
25 /*!
26  @brief Class that represents time.
27 */
29 {
30 public:
31 /*!
32  @brief Instantiates an object with default parameters (default constructor).
33 */
35  m_Year(0), m_Month(0), m_Day(0),
36  m_Hour(0), m_Minute(0), m_Second(0),
37  m_IsRegistered(false)
38  {
39  }
40 
41 /*!
42  @brief The copy constructor.
43 
44  @param[in] rhs Specifies the <tt>DateTime</tt> to copy.
45 */
46  DateTime(const DateTime& rhs)
47  {
48  m_Year = rhs.m_Year;
49  m_Month = rhs.m_Month;
50  m_Day = rhs.m_Day;
51  m_Hour = rhs.m_Hour;
52  m_Minute = rhs.m_Minute;
53  m_Second = rhs.m_Second;
54  m_IsRegistered = rhs.m_IsRegistered;
55  }
56 
57 /*!
58  @brief Instantiates an object with the specified date and time.
59 
60  @param[in] year Year.
61  @param[in] month Month.
62  @param[in] day Day.
63  @param[in] hour Hour.
64  @param[in] minute Minutes.
65  @param[in] second Seconds.
66 */
67  DateTime(u16 year, u8 month, u8 day, u8 hour, u8 minute, u8 second)
68  {
69  m_Year = year;
70  m_Month = month;
71  m_Day = day;
72  m_Hour = hour;
73  m_Minute = minute;
74  m_Second = second;
75  m_IsRegistered = true;
76  }
77 
78 /*!
79  @brief Assignment operator.
80  @param[in] rhs Assignment date and time.
81 */
83  {
84  m_Year = rhs.m_Year;
85  m_Month = rhs.m_Month;
86  m_Day = rhs.m_Day;
87  m_Hour = rhs.m_Hour;
88  m_Minute = rhs.m_Minute;
89  m_Second = rhs.m_Second;
90  m_IsRegistered = rhs.m_IsRegistered;
91  return *this;
92  }
93 
94 /*!
95  @brief Specifies the year.
96  @details Specify a value in the range from 1 to 9999.
97  @param[in] year Year.
98 */
99  void SetYear(u16 year)
100  {
101  m_Year = year;
102  m_IsRegistered = true;
103  }
104 
105 /*!
106  @brief Gets the specified year.
107  @return Returns the specified year.
108 */
109  u16 GetYear() const
110  {
111  return m_Year;
112  }
113 
114 /*!
115  @brief Specifies the month.
116  @details Specify a value in the range from 1 to 12.
117  @param[in] month Month.
118 */
119  void SetMonth(u8 month)
120  {
121  m_Month = month;
122  m_IsRegistered = true;
123  }
124 
125 /*!
126  @brief Gets the specified month.
127  @return Returns the specified month.
128 */
129  u8 GetMonth() const
130  {
131  return m_Month;
132  }
133 
134 /*!
135  @brief Specifies the day.
136  @details Specify a value in the range from 1 to 31.
137  @param[in] day Day.
138 */
139  void SetDay(u8 day)
140  {
141  m_Day = day;
142  m_IsRegistered = true;
143  }
144 
145 /*!
146  @brief Gets the specified day.
147  @return Returns the specified day.
148 */
149  u8 GetDay() const
150  {
151  return m_Day;
152  }
153 
154 /*!
155  @brief Specifies the hour.
156  @details Specify a value in the range from 0 to 23.
157  @param[in] hour Hour.
158 */
159  void SetHour(u8 hour)
160  {
161  m_Hour = hour;
162  m_IsRegistered = true;
163  }
164 
165 /*!
166  @brief Gets the specified hour.
167  @return Returns the specified hour.
168 */
169  u8 GetHour() const
170  {
171  return m_Hour;
172  }
173 
174 /*!
175  @brief Specifies the minutes.
176  @details Specify a value in the range from 0 to 59.
177  @param[in] minute Minutes.
178 */
179  void SetMinute(u8 minute)
180  {
181  m_Minute = minute;
182  m_IsRegistered = true;
183  }
184 
185 /*!
186  @brief Gets the specified minutes.
187  @return Returns the specified minutes.
188 */
189  u8 GetMinute() const
190  {
191  return m_Minute;
192  }
193 
194 /*!
195  @brief Specifies the seconds.
196  @details Specify a value in the range from 0 to 59.
197  @param[in] second Seconds.
198 */
199  void SetSecond(u8 second)
200  {
201  m_Second = second;
202  m_IsRegistered = true;
203  }
204 
205 /*!
206  @brief Gets the specified seconds.
207  @return Returns the specified seconds.
208 */
209  u8 GetSecond() const
210  {
211  return m_Second;
212  }
213 
214 /*!
215  @brief Gets whether a value has been specified.
216  @return Returns <tt>true</tt> if a value is specified.
217 */
218  bool IsRegistered() const
219  {
220  return m_IsRegistered;
221  }
222 
223 /*!
224  @brief Gets whether the specified date and time is correct.
225  @return Returns <tt>true</tt> if the specified date and time is correct.
226 */
227  bool IsValid() const
228  {
229  if (m_Year == 0 || m_Year > 9999)
230  {
231  return false;
232  }
233  if (m_Month == 0 || m_Month > 12)
234  {
235  return false;
236  }
237  if (m_Day == 0)
238  {
239  return false;
240  }
241  else if (m_Month == 2)
242  {
243  u8 days = (m_Year % 400 == 0 || (m_Year % 100 != 0 && m_Year % 4 == 0)) ? 29 : 28;
244  if (m_Day > days)
245  {
246  return false;
247  }
248  }
249  else if (m_Month == 4 || m_Month == 6 || m_Month == 9 || m_Month == 11)
250  {
251  if (m_Day > 30)
252  {
253  return false;
254  }
255  }
256  else
257  {
258  if (m_Day > 31)
259  {
260  return false;
261  }
262  }
263  if (m_Hour > 23)
264  {
265  return false;
266  }
267  if (m_Minute > 59)
268  {
269  return false;
270  }
271  if (m_Second > 59)
272  {
273  return false;
274  }
275  return true;
276  }
277 
278 /*!
279  @brief Clears the specified date and time.
280 */
281  void Clear()
282  {
283  m_Year = 0;
284  m_Month = 0;
285  m_Day = 0;
286  m_Hour = 0;
287  m_Minute = 0;
288  m_Second = 0;
289  m_IsRegistered = false;
290  }
291 
292 /*!
293  @brief The destructor.
294 */
295  virtual ~DateTime()
296  {
297  }
298 
299 private:
300  u16 m_Year; //!< 1-9999
301  u8 m_Month; //!< 1-12
302  u8 m_Day; //!< 1-31
303  u8 m_Hour; //!< 0-23
304  u8 m_Minute; //!< 0-59
305  u8 m_Second; //!< 0-59
306  bool m_IsRegistered;
307 };
308 
309 }
310 }
311 } // end of namespace nn::pia::common
bool IsRegistered() const
Gets whether a value has been specified.
Definition: common_DateTime.h:218
void SetDay(u8 day)
Specifies the day.
Definition: common_DateTime.h:139
Definition: assert.h:115
DateTime & operator=(const DateTime &rhs)
Assignment operator.
Definition: common_DateTime.h:82
bool IsValid() const
Gets whether the specified date and time is correct.
Definition: common_DateTime.h:227
u16 GetYear() const
Gets the specified year.
Definition: common_DateTime.h:109
DateTime()
Instantiates an object with default parameters (default constructor).
Definition: common_DateTime.h:34
u8 GetHour() const
Gets the specified hour.
Definition: common_DateTime.h:169
u8 GetMonth() const
Gets the specified month.
Definition: common_DateTime.h:129
u8 GetSecond() const
Gets the specified seconds.
Definition: common_DateTime.h:209
void SetHour(u8 hour)
Specifies the hour.
Definition: common_DateTime.h:159
void Clear()
Clears the specified date and time.
Definition: common_DateTime.h:281
void SetMonth(u8 month)
Specifies the month.
Definition: common_DateTime.h:119
u8 GetDay() const
Gets the specified day.
Definition: common_DateTime.h:149
virtual ~DateTime()
The destructor.
Definition: common_DateTime.h:295
DateTime(const DateTime &rhs)
The copy constructor.
Definition: common_DateTime.h:46
void SetYear(u16 year)
Specifies the year.
Definition: common_DateTime.h:99
DateTime(u16 year, u8 month, u8 day, u8 hour, u8 minute, u8 second)
Instantiates an object with the specified date and time.
Definition: common_DateTime.h:67
This is the common base class used inside the Pia library.
Definition: common_RootObject.h:40
u8 GetMinute() const
Gets the specified minutes.
Definition: common_DateTime.h:189
void SetSecond(u8 second)
Specifies the seconds.
Definition: common_DateTime.h:199
void SetMinute(u8 minute)
Specifies the minutes.
Definition: common_DateTime.h:179
Class that represents time.
Definition: common_DateTime.h:28