Sleds/libeye/eyetime.h

99 lines
3.0 KiB
C
Raw Normal View History

2025-03-13 21:28:38 +00:00
// Copyright (c) 2013-2015 IONU Security, Inc. All rights reserved.
//
// Time utility class
#ifndef eyetime_h
#define eyetime_h
#ifdef WIN32
# ifdef DLLEXPORT
# define LIBEYE_DLL __declspec(dllexport)
# else
# define LIBEYE_DLL __declspec(dllimport)
# endif
#else
#define LIBEYE_DLL
#endif
#ifdef WIN32
struct _SYSTEMTIME;
typedef _SYSTEMTIME SYSTEMTIME;
#endif
namespace sequencelogic {
// Time utility class
class EyeTime {
public:
LIBEYE_DLL EyeTime (const char* timestr);
LIBEYE_DLL EyeTime ();
LIBEYE_DLL ~EyeTime ();
LIBEYE_DLL bool SetTime (const char* timestr);
LIBEYE_DLL bool SetTime (time_t t);
#ifdef WIN32
LIBEYE_DLL bool EyeTime::SetTime (SYSTEMTIME sysTime);
#endif
LIBEYE_DLL bool SetTimeMs (long long tMs);
LIBEYE_DLL time_t GetTime();
#ifdef WIN32
LIBEYE_DLL SYSTEMTIME EyeTime::GetSysTime();
#endif
LIBEYE_DLL long long GetTimeMs();
LIBEYE_DLL bool GetFileTime (const std::string& path);
LIBEYE_DLL bool SetFileTime (const std::string& path);
LIBEYE_DLL const char* GetUnixTime ();
LIBEYE_DLL const char* GetISO8601Time ();
LIBEYE_DLL const char* GetISO8601TimeMs ();
LIBEYE_DLL const char* GetLocalISO8601Time ();
LIBEYE_DLL double SecondsFromNow ();
LIBEYE_DLL void Dump ();
LIBEYE_DLL int Compare (const EyeTime* other) const;
LIBEYE_DLL int Compare (const EyeTime& other) const { return Compare(&other); }
LIBEYE_DLL bool operator ==(const EyeTime* n) const { return Compare(n)==0; }
LIBEYE_DLL bool operator ==(const EyeTime& n) const { return Compare(n)==0; }
LIBEYE_DLL bool operator !=(const EyeTime* n) const { return Compare(n)!=0; }
LIBEYE_DLL bool operator !=(const EyeTime& n) const { return Compare(n)!=0; }
LIBEYE_DLL bool operator <(const EyeTime*n) const { return Compare(n)<0; }
LIBEYE_DLL bool operator <(const EyeTime&n) const { return Compare(n)<0; }
LIBEYE_DLL bool operator >(const EyeTime*n) const { return Compare(n)>0; }
LIBEYE_DLL bool operator >(const EyeTime&n) const { return Compare(n)>0; }
LIBEYE_DLL bool operator <=(const EyeTime*n) const { return Compare(n)<=0; }
LIBEYE_DLL bool operator <=(const EyeTime&n) const { return Compare(n)<=0; }
LIBEYE_DLL bool operator >=(const EyeTime*n) const { return Compare(n)>=0; }
LIBEYE_DLL bool operator >=(const EyeTime&n) const { return Compare(n)>=0; }
LIBEYE_DLL friend std::ostream& operator<< (std::ostream& stream, EyeTime& et);
private:
char _isodate[28];
unsigned int year;
unsigned int month;
unsigned int wday; // Day of the week
unsigned int day; // Day of the month
unsigned int yday; // Day of the year
unsigned int hour;
unsigned int minute;
unsigned int second;
unsigned int millisec;
int utc; // Offset from UTC (Zulu, GMT)
int daylight; // Daylight savings time offset
void Cap();
void SetWeekDay();
void SetYearDay();
void ConvertToLocalTime();
void ConvertToGMTime();
};
} //namespace sequencelogic
#endif