2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-23 18:07:00 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-23 18:07:00 +00:00
|
|
|
// TimeUtil.h
|
|
|
|
//
|
|
|
|
// Low-level date and time functions.
|
|
|
|
// Set and get time, format to string formats, count days and months etc.
|
|
|
|
//
|
|
|
|
|
2017-11-22 21:01:12 +00:00
|
|
|
#ifndef ES_CORE_UTILS_TIME_UTIL_H
|
|
|
|
#define ES_CORE_UTILS_TIME_UTIL_H
|
|
|
|
|
2020-11-26 17:53:00 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
|
|
|
#include <ctime>
|
|
|
|
#endif
|
|
|
|
|
2017-11-22 21:01:12 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace Utils
|
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
namespace Time
|
|
|
|
{
|
2020-08-02 13:56:32 +00:00
|
|
|
static int DEFAULT_TIMEVALUE = 0;
|
2020-06-23 18:07:00 +00:00
|
|
|
|
|
|
|
class DateTime
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DateTime();
|
|
|
|
DateTime(const time_t& _time);
|
|
|
|
DateTime(const tm& _timeStruct);
|
|
|
|
DateTime(const std::string& _isoString);
|
|
|
|
~DateTime();
|
|
|
|
|
|
|
|
const bool operator<(const DateTime& _other) const { return (mTime < _other.mTime); }
|
|
|
|
const bool operator<=(const DateTime& _other) const { return (mTime <= _other.mTime); }
|
|
|
|
const bool operator>(const DateTime& _other) const { return (mTime > _other.mTime); }
|
|
|
|
const bool operator>=(const DateTime& _other) const { return (mTime >= _other.mTime); }
|
|
|
|
operator time_t() const { return mTime; }
|
|
|
|
operator tm() const { return mTimeStruct; }
|
|
|
|
operator std::string() const { return mIsoString; }
|
|
|
|
|
|
|
|
void setTime(const time_t& _time);
|
|
|
|
const time_t& getTime() const { return mTime; }
|
|
|
|
void setTimeStruct(const tm& _timeStruct);
|
|
|
|
const tm& getTimeStruct() const { return mTimeStruct; }
|
|
|
|
void setIsoString (const std::string& _isoString);
|
|
|
|
const std::string& getIsoString () const { return mIsoString; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
time_t mTime;
|
|
|
|
tm mTimeStruct;
|
|
|
|
std::string mIsoString;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Duration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Duration(const time_t& _time);
|
|
|
|
~Duration();
|
|
|
|
|
|
|
|
unsigned int getDays() const { return mDays; }
|
|
|
|
unsigned int getHours() const { return mHours; }
|
|
|
|
unsigned int getMinutes() const { return mMinutes; }
|
|
|
|
unsigned int getSeconds() const { return mSeconds; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int mTotalSeconds;
|
|
|
|
unsigned int mDays;
|
|
|
|
unsigned int mHours;
|
|
|
|
unsigned int mMinutes;
|
|
|
|
unsigned int mSeconds;
|
|
|
|
};
|
|
|
|
|
|
|
|
time_t now();
|
|
|
|
time_t stringToTime(const std::string& _string,
|
|
|
|
const std::string& _format = "%Y%m%dT%H%M%S");
|
|
|
|
std::string timeToString(const time_t& _time,
|
|
|
|
const std::string& _format = "%Y%m%dT%H%M%S");
|
|
|
|
int daysInMonth(const int _year, const int _month);
|
|
|
|
int daysInYear(const int _year);
|
|
|
|
}
|
2017-11-22 21:01:12 +00:00
|
|
|
} // Utils::
|
|
|
|
|
|
|
|
#endif // ES_CORE_UTILS_TIME_UTIL_H
|