forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateTime.h
178 lines (163 loc) · 6.26 KB
/
DateTime.h
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
#ifndef DATE_TIME_H
#define DATE_TIME_H
#include "EnumHelper.h"
#include <ctime>
int StringToDayInYear( std::string sDayInYear );
/** @brief The number of days we check for previously. */
const int NUM_LAST_DAYS = 7;
/** @brief The number of weeks we check for previously. */
const int NUM_LAST_WEEKS = 52;
/**
* @brief The number of days that are in a year.
*
* This is set up to be a maximum for leap years. */
const int DAYS_IN_YEAR = 366;
/**
* @brief The number of hours in a day. */
const int HOURS_IN_DAY = 24;
/**
* @brief The number of days that are in a week. */
const int DAYS_IN_WEEK = 7;
/** @brief Which month are we focusing on?
*
* Is there any reason why the actual months aren't defined
* in here? -Wolfman2000 */
enum Month
{
NUM_Month = 12, /**< The number of months in the year. */
Month_Invalid /**< There should be no month at this point. */
};
std::string DayInYearToString( int iDayInYearIndex );
std::string LastDayToString( int iLastDayIndex );
std::string LastDayToLocalizedString( int iLastDayIndex );
std::string DayOfWeekToString( int iDayOfWeekIndex );
std::string DayOfWeekToLocalizedString( int iDayOfWeekIndex );
std::string HourInDayToString( int iHourIndex );
std::string HourInDayToLocalizedString( int iHourIndex );
std::string const MonthToString( Month month );
std::string const MonthToLocalizedString( Month month );
std::string LastWeekToString( int iLastWeekIndex );
std::string LastWeekToLocalizedString( int iLastWeekIndex );
LuaDeclareType( Month );
tm AddDays( tm start, int iDaysToMove );
tm GetYesterday( tm start );
int GetDayOfWeek( tm time );
tm GetNextSunday( tm start );
tm GetDayInYearAndYear( int iDayInYearIndex, int iYear );
/** @brief A standard way of determining the date and the time. */
struct DateTime
{
/**
* @brief The number of seconds after the minute.
*
* Valid values are [0, 59]. */
int tm_sec;
/**
* @brief The number of minutes after the hour.
*
* Valid values are [0, 59]. */
int tm_min;
/**
* @brief The number of hours since midnight (or 0000 hours).
*
* Valid values are [0, 23]. */
int tm_hour;
/**
* @brief The specified day of the current month.
*
* Valid values are [1, 31].
*
* XXX: Is it possible to set an illegal date through here,
* such as day 30 of February? -Wolfman2000 */
int tm_mday;
/**
* @brief The number of months since January.
*
* Valid values are [0, 11]. */
int tm_mon;
/** @brief The number of years since the year 1900. */
int tm_year;
/** @brief Set up a default date and time. */
DateTime();
/** @brief Initialize the date and time. */
void Init();
/**
* @brief Determine if this DateTime is less than some other time.
* @param other the other DateTime to check.
* @return true if this is less than the other time, or false otherwise. */
bool operator<( const DateTime& other ) const;
/**
* @brief Determine if this DateTime is greater than some other time.
* @param other the other DateTime to check.
* @return true if this is greater than the other time, or false otherwise. */
bool operator>( const DateTime& other ) const;
/**
* @brief Determine if this DateTime is equal to some other time.
* @param other the other DateTime to check.
* @return true if this is equal to the other time, or false otherwise. */
bool operator==( const DateTime& other ) const;
/**
* @brief Determine if this DateTime is not equal to some other time.
* @param other the other DateTime to check.
* @return true if this is not equal to the other time, or false otherwise. */
bool operator!=( const DateTime& other ) const { return !operator==(other); }
/**
* @brief Determine if this DateTime is less than or equal to some other time.
* @param other the other DateTime to check.
* @return true if this is less than or equal to the other time, or false otherwise. */
bool operator<=( const DateTime& other ) const { return !operator>(other); }
/**
* @brief Determine if this DateTime is greater than or equal to some other time.
* @param other the other DateTime to check.
* @return true if this is greater than or equal to the other time, or false otherwise. */
bool operator>=( const DateTime& other ) const { return !operator<(other); }
/**
* @brief Retrieve the current date and time.
* @return the current date and time. */
static DateTime GetNowDateTime();
/**
* @brief Retrieve the current date.
* @return the current date. */
static DateTime GetNowDate();
/** @brief Remove the time portion from the date. */
void StripTime();
/**
* @brief Retrieve a string representation of the current date and time.
*
* This returns a common SQL/XML format: "YYYY-MM-DD HH:MM:SS".
* @return the string representation of the date and time. */
std::string GetString() const;
/**
* @brief Attempt to turn a string into a DateTime.
*
* @param sDateTime the string to attempt to convert.
* @return true if the conversion worked, or false otherwise. */
bool FromString( const std::string sDateTime );
};
#endif
/**
* @file
* @author Chris Danford (c) 2001-2004
* @section LICENSE
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/