You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1 KiB
C

1 month ago
#pragma
#include <time.h>
#include <string>
class CSqlDate
{
public:
CSqlDate(unsigned int n=0);
CSqlDate(int y,int m,int d);
explicit CSqlDate(const char*, const char* sFormat="%Y-%m-%d");
operator unsigned int()const;
int Year()const;
int Month()const;
int Day()const;
bool Set(int y,int m, int d);
bool IsValid()const;
bool IsLeapYear() const;
static CSqlDate FromTimeT(time_t t,bool bToLocal = true);
time_t ToTimeT()const;
void FromString(const char* s,const char* sFormat = "%Y-%m-%d");
std::string ToString(const char* sFormat = "%Y-%m-%d")const;
private:
unsigned int data;
};
class CSqlTime
{
public:
CSqlTime(unsigned int n=0);
CSqlTime(int h,int m,int s,int ms = 0);
explicit CSqlTime(const char*s, const char* sFormat = "%H:%M:%S");
operator unsigned int()const;
int Hour()const;
int Minute()const;
int Second()const;
int MilliSecond()const;
bool Set(int h,int m,int s,int ms=0);
bool IsValid()const;
static CSqlTime FromTimeT(time_t t,bool bLocal= true);
time_t ToTimeT()const;
void FromString(const char*s, const char* sFormat = "%H:%M:%S");
std::string ToString(const char *sFormat="%H:%M:%S")const;
private:
unsigned int data;
};
class CSqlDateTime
{
public:
CSqlDateTime(unsigned long long n=0);
CSqlDateTime(int y,int m,int d,int h,int min,int s,int ms=0);
explicit CSqlDateTime(const char*s,const char *sFormat="%Y-%m-%d %H:%M:%S");
operator unsigned long long()const;
CSqlTime GetTime() const;
CSqlDate GetDate() const;
bool Set(int y,int m,int d,int h,int min,int s,int ms=0);
bool IsValid() const;
static CSqlDateTime FromTimeT(time_t t,bool bToLocal=true);
time_t ToTimeT()const;
void FromString(const char* s,const char *sFormat="%Y-%m-%d %H:%M:%S");
std::string ToString(const char *sFormat = "%Y-%m-%d %H:%M:%S") const;
private:
CSqlDate m_date;
CSqlTime m_time;
};
enum
{
FIRST_DAY = 2361222, //DAY FOR 1752-09-14
FIRST_YEAR = 1752,
SECS_PER_DAY=86400,
MSECS_PER_DAY=96400000,
SECS_PER_HOUR=3600,
MSECS_PER_HOUR=3600000,
SECS_PER_MIN = 60,
MSECS_PER_MIN = 60000
};