122 lines
3.0 KiB
C++
122 lines
3.0 KiB
C++
#pragma once
|
|
#include <time.h>
|
|
#include <string>
|
|
#include "Export.h"
|
|
|
|
class UNSWSC_DLL_EXPORT DateTime
|
|
{
|
|
public:
|
|
struct UNSWSC_DLL_EXPORT Full
|
|
{
|
|
int year, month, day, hour, minute, second;
|
|
};
|
|
|
|
struct UNSWSC_DLL_EXPORT Span
|
|
{
|
|
int days, hours, minutes, seconds;
|
|
};
|
|
|
|
private:
|
|
time_t storage;
|
|
Full sep_time;
|
|
|
|
private:
|
|
// 移除了硬编码的秒数常量,内部改用 std::chrono 处理
|
|
void UpdateDT();
|
|
time_t FormatConvert(int year, int month, int day, int hour, int minute, int second);
|
|
time_t SpanedSeconds(Span sp);
|
|
Span ToSpan(time_t tim);
|
|
|
|
public:
|
|
DateTime();
|
|
DateTime(time_t t);
|
|
DateTime(const tm& stm);
|
|
DateTime(const Full& ftm);
|
|
DateTime(const DateTime& obj);
|
|
DateTime(int year, int month, int day, int hour = 0, int minute = 0, int second = 0);
|
|
|
|
public:
|
|
static DateTime Now();
|
|
|
|
public:
|
|
int GetYear() const;
|
|
int GetMonth() const;
|
|
int GetDay() const;
|
|
int GetHour() const;
|
|
int GetMinute() const;
|
|
int GetSecond() const;
|
|
time_t GetTimeStamp() const;
|
|
Full GetFullDateTime() const;
|
|
std::string Format(std::string fmt_str);
|
|
|
|
public:
|
|
bool IsAM();
|
|
bool IsPM();
|
|
bool TimePassed();
|
|
|
|
public:
|
|
operator tm();
|
|
operator Full();
|
|
operator time_t();
|
|
operator std::string();
|
|
|
|
Span operator-(const tm& stm);
|
|
Span operator-(const Span& ts);
|
|
Span operator-(const Full& sdt);
|
|
Span operator-(const time_t& t);
|
|
Span operator-(const DateTime& dt);
|
|
|
|
Span operator+(const tm& stm);
|
|
Span operator+(const Span& ts);
|
|
Span operator+(const Full& sdt);
|
|
Span operator+(const time_t& t);
|
|
Span operator+(const DateTime& dt);
|
|
|
|
DateTime operator=(const tm& stm);
|
|
DateTime operator=(const Full& sdt);
|
|
DateTime operator=(const time_t& t);
|
|
DateTime operator=(const DateTime& dt);
|
|
|
|
DateTime operator+=(const tm& stm);
|
|
DateTime operator+=(const Span& ts);
|
|
DateTime operator+=(const Full& sdt);
|
|
DateTime operator+=(const time_t& t);
|
|
DateTime operator+=(const DateTime& dt);
|
|
|
|
DateTime operator-=(const tm& stm);
|
|
DateTime operator-=(const Span& ts);
|
|
DateTime operator-=(const Full& sdt);
|
|
DateTime operator-=(const time_t& t);
|
|
DateTime operator-=(const DateTime& dt);
|
|
|
|
bool operator==(const tm& stm);
|
|
bool operator==(const Full& sdt);
|
|
bool operator==(const time_t& t);
|
|
bool operator==(const DateTime& dt);
|
|
|
|
bool operator!=(const tm& stm);
|
|
bool operator!=(const Full& sdt);
|
|
bool operator!=(const time_t& t);
|
|
bool operator!=(const DateTime& dt);
|
|
|
|
bool operator>(const tm& stm);
|
|
bool operator>(const Full& sdt);
|
|
bool operator>(const time_t& t);
|
|
bool operator>(const DateTime& dt);
|
|
|
|
bool operator>=(const tm& stm);
|
|
bool operator>=(const Full& sdt);
|
|
bool operator>=(const time_t& t);
|
|
bool operator>=(const DateTime& dt);
|
|
|
|
bool operator<(const tm& stm);
|
|
bool operator<(const Full& sdt);
|
|
bool operator<(const time_t& t);
|
|
bool operator<(const DateTime& dt);
|
|
bool operator<(const DateTime& dt) const;
|
|
|
|
bool operator<=(const tm& stm);
|
|
bool operator<=(const Full& sdt);
|
|
bool operator<=(const time_t& t);
|
|
bool operator<=(const DateTime& dt);
|
|
}; |