CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
common_DateTime.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/common/common_Definitions.h>
17 
18 namespace nn
19 {
20 namespace pia
21 {
22 namespace common
23 {
24 /*!
25  @brief 日時を表すクラスです。
26  */
28 {
29 public:
30  /*!
31  @brief デフォルトコンストラクタです。
32  */
34  : m_Year(0), m_Month(0), m_Day(0), m_Hour(0), m_Minute(0), m_Second(0), m_IsRegistered(false)
35  {
36  }
37 
38  /*!
39  @brief コピーコンストラクタです。
40 
41  @param[in] rhs コピーする DateTime です。
42  */
43  DateTime(const DateTime& rhs)
44  {
45  m_Year = rhs.m_Year;
46  m_Month = rhs.m_Month;
47  m_Day = rhs.m_Day;
48  m_Hour = rhs.m_Hour;
49  m_Minute = rhs.m_Minute;
50  m_Second = rhs.m_Second;
51  m_IsRegistered = rhs.m_IsRegistered;
52  }
53 
54  /*!
55  @brief 指定日時で構築するコンストラクタです。
56 
57  @param[in] year 年
58  @param[in] month 月
59  @param[in] day 日
60  @param[in] hour 時
61  @param[in] minute 分
62  @param[in] second 秒
63  */
64  DateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
65  {
66  m_Year = year;
67  m_Month = month;
68  m_Day = day;
69  m_Hour = hour;
70  m_Minute = minute;
71  m_Second = second;
72  m_IsRegistered = true;
73  }
74 
75  /*!
76  @brief 代入演算子です。
77  @param[in] rhs 代入する日時です。
78  */
80  {
81  m_Year = rhs.m_Year;
82  m_Month = rhs.m_Month;
83  m_Day = rhs.m_Day;
84  m_Hour = rhs.m_Hour;
85  m_Minute = rhs.m_Minute;
86  m_Second = rhs.m_Second;
87  m_IsRegistered = rhs.m_IsRegistered;
88  return *this;
89  }
90 
91  /*!
92  @brief 年を指定します。
93  @details 1-9999 までを指定する必要があります。
94  @param[in] year 年
95  */
96  void SetYear(uint16_t year)
97  {
98  m_Year = year;
99  m_IsRegistered = true;
100  }
101 
102  /*!
103  @brief 指定された年を取得します。
104  @return 指定された年を返します。
105  */
106  uint16_t GetYear() const
107  {
108  return m_Year;
109  }
110 
111  /*!
112  @brief 月を指定します。
113  @details 1-12 までを指定する必要があります。
114  @param[in] month 月
115  */
116  void SetMonth(uint8_t month)
117  {
118  m_Month = month;
119  m_IsRegistered = true;
120  }
121 
122  /*!
123  @brief 指定された月を取得します。
124  @return 指定された月を返します。
125  */
126  uint8_t GetMonth() const
127  {
128  return m_Month;
129  }
130 
131  /*!
132  @brief 日を指定します。
133  @details 1-31 までを指定する必要があります。
134  @param[in] day 日
135  */
136  void SetDay(uint8_t day)
137  {
138  m_Day = day;
139  m_IsRegistered = true;
140  }
141 
142  /*!
143  @brief 指定された日を取得します。
144  @return 指定された日を返します。
145  */
146  uint8_t GetDay() const
147  {
148  return m_Day;
149  }
150 
151  /*!
152  @brief 時を指定します。
153  @details 0-23 までを指定する必要があります。
154  @param[in] hour 時
155  */
156  void SetHour(uint8_t hour)
157  {
158  m_Hour = hour;
159  m_IsRegistered = true;
160  }
161 
162  /*!
163  @brief 指定された時を取得します。
164  @return 指定された時を返します。
165  */
166  uint8_t GetHour() const
167  {
168  return m_Hour;
169  }
170 
171  /*!
172  @brief 分を指定します。
173  @details 0-59 までを指定する必要があります。
174  @param[in] minute 分
175  */
176  void SetMinute(uint8_t minute)
177  {
178  m_Minute = minute;
179  m_IsRegistered = true;
180  }
181 
182  /*!
183  @brief 指定された分を取得します。
184  @return 指定された分を返します。
185  */
186  uint8_t GetMinute() const
187  {
188  return m_Minute;
189  }
190 
191  /*!
192  @brief 秒を指定します。
193  @details 0-59 までを指定する必要があります。
194  @param[in] second 秒
195  */
196  void SetSecond(uint8_t second)
197  {
198  m_Second = second;
199  m_IsRegistered = true;
200  }
201 
202  /*!
203  @brief 指定された秒を取得します。
204  @return 指定された秒を返します。
205  */
206  uint8_t GetSecond() const
207  {
208  return m_Second;
209  }
210 
211  /*!
212  @brief 値が指定されたかどうかを取得します。。
213  @return 値が指定されていたら true を返します。
214  */
215  bool IsRegistered() const
216  {
217  return m_IsRegistered;
218  }
219 
220  /*!
221  @brief 指定された日時が正しいかどうかを取得します。。
222  @return 指定された日時が正しければ true を返します。
223  */
224  bool IsValid() const
225  {
226  if (m_Year == 0 || m_Year > 9999)
227  {
228  return false;
229  }
230  if (m_Month == 0 || m_Month > 12)
231  {
232  return false;
233  }
234  if (m_Day == 0)
235  {
236  return false;
237  }
238  else if (m_Month == 2)
239  {
240  uint8_t days = (m_Year % 400 == 0 || (m_Year % 100 != 0 && m_Year % 4 == 0)) ? 29 : 28;
241  if (m_Day > days)
242  {
243  return false;
244  }
245  }
246  else if (m_Month == 4 || m_Month == 6 || m_Month == 9 || m_Month == 11)
247  {
248  if (m_Day > 30)
249  {
250  return false;
251  }
252  }
253  else
254  {
255  if (m_Day > 31)
256  {
257  return false;
258  }
259  }
260  if (m_Hour > 23)
261  {
262  return false;
263  }
264  if (m_Minute > 59)
265  {
266  return false;
267  }
268  if (m_Second > 59)
269  {
270  return false;
271  }
272  return true;
273  }
274 
275  /*!
276  @brief 指定した日時をクリアします。
277  */
278  void Clear()
279  {
280  m_Year = 0;
281  m_Month = 0;
282  m_Day = 0;
283  m_Hour = 0;
284  m_Minute = 0;
285  m_Second = 0;
286  m_IsRegistered = false;
287  }
288 
289  /*!
290  @brief 指定した日時を値として取得します。
291  @return 指定した日時を値として返します。
292  */
293  uint64_t GetValue() const
294  {
295  return (static_cast<uint64_t>(m_Year) << 40) |
296  (static_cast<uint64_t>(m_Month) << 32) |
297  (static_cast<uint64_t>(m_Day) << 24) |
298  (static_cast<uint64_t>(m_Hour) << 16) |
299  (static_cast<uint64_t>(m_Minute) << 8) |
300  (static_cast<uint64_t>(m_Second));
301  }
302 
303  /*!
304  @brief デストラクタです。
305  */
306  virtual ~DateTime()
307  {
308  }
309 
310 private:
311  uint16_t m_Year; //!< 1-9999
312  uint8_t m_Month; //!< 1-12
313  uint8_t m_Day; //!< 1-31
314  uint8_t m_Hour; //!< 0-23
315  uint8_t m_Minute; //!< 0-59
316  uint8_t m_Second; //!< 0-59
317  bool m_IsRegistered;
318 };
319 }
320 }
321 } // end of namespace nn::pia::common