Etterna 0.74.4
Loading...
Searching...
No Matches
DateTime.h
1#ifndef DATE_TIME_H
2#define DATE_TIME_H
3
4#include "EnumHelper.h"
5#include <ctime>
6
7auto
8StringToDayInYear(const std::string& sDayInYear) -> int;
9
11const int NUM_LAST_DAYS = 7;
13const int NUM_LAST_WEEKS = 52;
18const int DAYS_IN_YEAR = 366;
21const int HOURS_IN_DAY = 24;
24const int DAYS_IN_WEEK = 7;
25enum Month
26{
27 Month_January,
28 Month_February,
29 Month_March,
30 Month_April,
31 Month_May,
32 Month_June,
33 Month_July,
34 Month_August,
35 Month_September,
36 Month_October,
37 Month_November,
38 Month_December,
39 NUM_Month = 12,
40 Month_Invalid
41};
42
43auto
44DayInYearToString(int iDayInYearIndex) -> std::string;
45auto
46LastDayToString(int iLastDayIndex) -> std::string;
47auto
48LastDayToLocalizedString(int iLastDayIndex) -> std::string;
49auto
50DayOfWeekToString(int iDayOfWeekIndex) -> std::string;
51auto
52DayOfWeekToLocalizedString(int iDayOfWeekIndex) -> std::string;
53auto
54HourInDayToString(int iHourIndex) -> std::string;
55auto
56HourInDayToLocalizedString(int iHourIndex) -> std::string;
57auto
58MonthToString(Month month) -> const std::string&;
59auto
60MonthToLocalizedString(Month month) -> const std::string&;
61auto
62LastWeekToString(int iLastWeekIndex) -> std::string;
63auto
64LastWeekToLocalizedString(int iLastWeekIndex) -> std::string;
65LuaDeclareType(Month);
66
67auto
68AddDays(tm start, int iDaysToMove) -> tm;
69auto
70GetYesterday(tm start) -> tm;
71auto
72GetDayOfWeek(tm time) -> int;
73auto
74GetNextSunday(tm start) -> tm;
75
76auto
77GetDayInYearAndYear(int iDayInYearIndex, int iYear) -> tm;
78
81{
86 int tm_sec;
91 int tm_min;
112
114 DateTime();
116 void Init();
117
122 auto operator<(const DateTime& other) const -> bool;
128 auto operator>(const DateTime& other) const -> bool;
133 auto operator==(const DateTime& other) const -> bool;
139 auto operator!=(const DateTime& other) const -> bool
140 {
141 return !operator==(other);
142 }
149 auto operator<=(const DateTime& other) const -> bool
150 {
151 return !operator>(other);
152 }
153
160 auto operator>=(const DateTime& other) const -> bool
161 {
162 return !operator<(other);
163 }
164
168 static auto GetNowDateTime() -> DateTime;
172 static auto GetNowDate() -> DateTime;
173
174 static auto GetFromString(const std::string& str) -> DateTime;
175
176 static auto GetYesterday() -> DateTime;
177
179 void StripTime();
180
186 [[nodiscard]] auto GetString() const -> std::string;
192 auto FromString(const std::string& sDateTime) -> bool;
193};
194
195#endif
A standard way of determining the date and the time.
Definition DateTime.h:81
int tm_mday
The specified day of the current month.
Definition DateTime.h:104
int tm_mon
The number of months since January.
Definition DateTime.h:109
auto FromString(const std::string &sDateTime) -> bool
Attempt to turn a string into a DateTime.
Definition DateTime.cpp:127
int tm_sec
The number of seconds after the minute.
Definition DateTime.h:86
DateTime()
Set up a default date and time.
Definition DateTime.cpp:10
int tm_hour
The number of hours since midnight (or 0000 hours).
Definition DateTime.h:96
static auto GetNowDateTime() -> DateTime
Retrieve the current date and time.
Definition DateTime.cpp:72
int tm_min
The number of minutes after the hour.
Definition DateTime.h:91
static auto GetNowDate() -> DateTime
Retrieve the current date.
Definition DateTime.cpp:90
int tm_year
The number of years since the year 1900.
Definition DateTime.h:111
auto operator>=(const DateTime &other) const -> bool
Determine if this DateTime is greater than or equal to some other time.
Definition DateTime.h:160
auto operator==(const DateTime &other) const -> bool
Determine if this DateTime is equal to some other time.
Definition DateTime.cpp:39
void StripTime()
Remove the time portion from the date.
Definition DateTime.cpp:106
auto GetString() const -> std::string
Retrieve a string representation of the current date and time.
Definition DateTime.cpp:115
void Init()
Initialize the date and time.
Definition DateTime.cpp:16
auto operator<(const DateTime &other) const -> bool
Determine if this DateTime is less than some other time.
Definition DateTime.cpp:22
auto operator>(const DateTime &other) const -> bool
Determine if this DateTime is greater than some other time.
Definition DateTime.cpp:55
auto operator!=(const DateTime &other) const -> bool
Determine if this DateTime is not equal to some other time.
Definition DateTime.h:139
auto operator<=(const DateTime &other) const -> bool
Determine if this DateTime is less than or equal to some other time.
Definition DateTime.h:149