1 /*---------------------------------------------------------------------------*
2 
3 Copyright (C) 2013-2014 Nintendo. All rights reserved.
4 
5 These coded instructions, statements, and computer programs contain
6 proprietary information of Nintendo of America Inc. and/or Nintendo
7 Company Ltd., and are protected by Federal copyright law.  They may
8 not be disclosed to third parties or copied or duplicated in any form,
9 in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 
13 #ifndef NN_EC_DATE_TIME_H_
14 #define NN_EC_DATE_TIME_H_
15 
16 #include <nn/ec/ec_Types.h>
17 
18 namespace nn { namespace ec {
19 
20 //! @addtogroup nn_ec_class
21 //! @{
22 
23 /*!
24 @brief Class for handling the date and time.
25 */
26 class DateTime : public RootObject
27 {
28 public:
29     /*!
30 @brief      The day of the week.
31     */
32     enum Week
33     {
34         WEEK_SUNDAY    = 0, //!< Sunday.
35         WEEK_MONDAY    = 1, //!< Monday.
36         WEEK_TUESDAY   = 2, //!< Tuesday.
37         WEEK_WEDNESDAY = 3, //!< Wednesday.
38         WEEK_THURSDAY  = 4, //!< Thursday.
39         WEEK_FRIDAY    = 5, //!< Friday.
40         WEEK_SATURDAY  = 6, //!< Saturday.
41 
42         WEEK_MAX,
43         WEEK_FORCE_S32 = 0x7FFFFFFF
44     };
45 
46 public:
47     /*!
48 @brief Instantiates the object.
49 
50 The initial value is set to 2010-01-01 00:00:00.
51     */
52     DateTime();
53 
54     /*!
55 @brief Instantiates the object.
56 
57 @param[in] pFormatted  Specifies a formatted string. @n
58 The "YYYY-MM-DD" and "YYYY-MM-DD hh:mm:ss" formats are supported.
59     */
60     DateTime(const char* pFormatted);
61 
62     /*!
63 @brief Instantiates the object.
64 
65 @param[in] year  Specifies the year. @n
66 The valid range is from 0 through 9999.
67 @param[in] month  Specifies the month. @n
68 The valid range is from 1 through 12.
69 @param[in] day  Specifies the day. @n
70 The valid range is from 1 through 31.
71 @param[in] hour  Specifies the hour. @n
72 The valid range is from 0 through 23.
73 @param[in] minute  Specifies the minute. @n
74 The valid range is from 0 through 59.
75 @param[in] second  Specifies the second. @n
76 The valid range is from 0 through 59.
77     */
78     DateTime(u16 year, u8 month, u8 day, u8 hour = 0, u8 minute = 0, u8 second = 0);
79 
80     /*!
81 @brief Gets the year.
82 
83 The valid range is from 0 through 9999.
84 
85 @return Returns the year.
86     */
87     u16 GetYear() const;
88 
89     /*!
90 @brief Gets the month.
91 
92 The valid range is from 1 through 12.
93 
94 @return Returns the month.
95     */
96     u8 GetMonth() const;
97 
98     /*!
99 @brief Gets the day.
100 
101 The valid range is from 1 through 31.
102 
103 @return Returns the day.
104     */
105     u8 GetDay() const;
106 
107     /*!
108 @brief Gets the hour.
109 
110 The valid range is from 0 through 23.
111 
112 @return Returns the hour.
113     */
114     u8 GetHour() const;
115 
116     /*!
117 @brief Gets the minute.
118 
119 The valid range is from 0 through 59.
120 
121 @return Returns the minute.
122     */
123     u8 GetMinute() const;
124 
125     /*!
126 @brief Gets the second.
127 
128 The valid range is from 0 through 59.
129 
130 @return Returns the second.
131     */
132     u8 GetSecond() const;
133 
134     /*!
135 @brief Gets the name of the day of the week.
136 
137 @return Returns the day of the week.
138     */
139     Week GetWeek() const;
140 
141     /*!
142 @brief Compares two <tt>DateTime</tt> objects.
143 
144 @param[in] dateTime  Specifies the date and time to compare.
145 
146 @return Returns the result of an equality (<tt>==</tt>) operation.
147     */
148     bool operator==(const DateTime& dateTime) const;
149 
150     /*!
151 @brief Compares two <tt>DateTime</tt> objects.
152 
153 @param[in] dateTime  Specifies the date and time to compare.
154 
155 @return Returns the result of an inequality (<tt>!=</tt>) operation.
156     */
157     bool operator!=(const DateTime& dateTime) const;
158 
159     /*!
160 @brief Compares two <tt>DateTime</tt> objects.
161 
162 @param[in] dateTime  Specifies the date and time to compare.
163 
164 @return Returns the result of a greater than (<tt>></tt>) operation.
165     */
166     bool operator>(const DateTime& dateTime) const;
167 
168     /*!
169 @brief Compares two <tt>DateTime</tt> objects.
170 
171 @param[in] dateTime  Specifies the date and time to compare.
172 
173 @return Returns the result of a less than (<tt><</tt>) operation.
174     */
175     bool operator<(const DateTime& dateTime) const;
176 
177     /*!
178 @brief Compares two <tt>DateTime</tt> objects.
179 
180 @param[in] dateTime  Specifies the date and time to compare.
181 
182 @return Returns the result of a greater-than-or-equal-to (<tt>>=</tt>) operation.
183     */
184     bool operator>=(const DateTime& dateTime) const;
185 
186     /*!
187 @brief Compares two <tt>DateTime</tt> objects.
188 
189 @param[in] dateTime  Specifies the date and time to compare.
190 
191 @return Returns the result of a less-than-or-equal-to (<tt><=</tt>) operation.
192     */
193     bool operator<=(const DateTime& dateTime) const;
194 
195     /*!
196 @brief Adds time.
197 
198 @param[in] seconds  Specifies the amount of time to add.
199 
200 @return Returns the date and time.
201     */
202     const DateTime operator+(s64 seconds) const;
203 
204     /*!
205 @brief Subtracts time.
206 
207 @param[in] seconds  Specifies the amount of time to subtract.
208 
209 @return Returns the date and time.
210     */
211     const DateTime operator-(s64 seconds) const;
212 
213     /*!
214 @brief Subtracts one <tt>DateTime</tt> object from another and calculates the time difference.
215 
216 The time difference is returned as seconds.
217 
218 @param[in] dateTime  Specifies the date and time to compare.
219 
220 @return Returns the time difference.
221     */
222     s64 operator-(const DateTime& dateTime) const;
223 
224     /*!
225 @brief Adds time.
226 
227 @param[in] seconds  Specifies the amount of time to add.
228 
229 @return Returns the date and time.
230     */
231     DateTime& operator+=(s64 seconds);
232 
233     /*!
234 @brief Subtracts time.
235 
236 @param[in] seconds  Specifies the amount of time to subtract.
237 
238 @return Returns the date and time.
239     */
240     DateTime& operator-=(s64 seconds);
241 
242 private:
243     // 0-9999
244     u16 m_year;
245     // 1-12
246     u8 m_month;
247     // 1-31
248     u8 m_day;
249     // 0-23
250     u8 m_hour;
251     // 0-59
252     u8 m_minute;
253     // 0-59
254     u8 m_second;
255     //
256     u8 m_week;
257 };
258 
259 //! @}
260 
261 }} // namespace nn::ec
262 
263 #endif // NN_EC_DATE_TIME_H_
264