Don't use SDL typedefs in DateTime.h

master
Webster Sheets 2020-05-13 23:24:23 -04:00
parent 59cafb1b95
commit bd338bae29
1 changed files with 17 additions and 18 deletions

View File

@ -1,7 +1,6 @@
#ifndef DATETIME_H
#define DATETIME_H
#include <SDL_stdinc.h>
#include <string>
namespace Time {
@ -29,7 +28,7 @@ namespace Time {
// and the passage of time. For example, leap seconds are not supported at all.
// But... I'm pretty sure we don't need leap seconds for Pioneer.
enum TimeUnit : Sint64 {
enum TimeUnit : int64_t {
Microsecond = 1ll,
Millisecond = 1000ll * Microsecond,
Second = 1000ll * Millisecond,
@ -46,16 +45,16 @@ namespace Time {
public:
TimeDelta() :
m_delta(0) {}
explicit TimeDelta(Sint64 t, TimeUnit unit = Second) :
explicit TimeDelta(int64_t t, TimeUnit unit = Second) :
m_delta(t * unit) {}
Sint64 GetTotalWeeks() const { return (m_delta / Week); }
Sint64 GetTotalDays() const { return (m_delta / Day); }
Sint64 GetTotalHours() const { return (m_delta / Hour); }
Sint64 GetTotalMinutes() const { return (m_delta / Minute); }
Sint64 GetTotalSeconds() const { return (m_delta / Second); }
Sint64 GetTotalMilliseconds() const { return (m_delta / Millisecond); }
Sint64 GetTotalMicroseconds() const { return (m_delta / Microsecond); }
int64_t GetTotalWeeks() const { return (m_delta / Week); }
int64_t GetTotalDays() const { return (m_delta / Day); }
int64_t GetTotalHours() const { return (m_delta / Hour); }
int64_t GetTotalMinutes() const { return (m_delta / Minute); }
int64_t GetTotalSeconds() const { return (m_delta / Second); }
int64_t GetTotalMilliseconds() const { return (m_delta / Millisecond); }
int64_t GetTotalMicroseconds() const { return (m_delta / Microsecond); }
TimeDelta &operator+=(const TimeDelta &x)
{
@ -70,22 +69,22 @@ namespace Time {
friend TimeDelta operator+(const TimeDelta &a, const TimeDelta &b) { return TimeDelta(a.m_delta + b.m_delta, TimeUnit(1)); }
friend TimeDelta operator-(const TimeDelta &a, const TimeDelta &b) { return TimeDelta(a.m_delta - b.m_delta, TimeUnit(1)); }
friend TimeDelta operator*(Sint64 x, const TimeDelta &t) { return TimeDelta(x * t.m_delta, TimeUnit(1)); }
friend TimeDelta operator/(const TimeDelta &t, Sint64 x) { return TimeDelta(t.m_delta / x, TimeUnit(1)); }
friend Sint64 operator/(const TimeDelta &a, const TimeDelta &b) { return (a.m_delta / b.m_delta); }
friend TimeDelta operator*(int64_t x, const TimeDelta &t) { return TimeDelta(x * t.m_delta, TimeUnit(1)); }
friend TimeDelta operator/(const TimeDelta &t, int64_t x) { return TimeDelta(t.m_delta / x, TimeUnit(1)); }
friend int64_t operator/(const TimeDelta &a, const TimeDelta &b) { return (a.m_delta / b.m_delta); }
friend DateTime operator+(const DateTime &a, const TimeDelta &b);
friend DateTime operator-(const DateTime &a, const TimeDelta &b);
private:
friend class DateTime;
Sint64 m_delta;
int64_t m_delta;
};
class DateTime {
public:
DateTime() :
m_timestamp(-Sint64(24 * 60 * 60) * Sint64(400 * 365 + 97) * Sint64(Second)) {}
m_timestamp(-int64_t(24 * 60 * 60) * int64_t(400 * 365 + 97) * int64_t(Second)) {}
// month = 1 to 12
// day = 1 to N where N is the number of days in the specified month and year
DateTime(int year, int month, int day, int hour = 0, int minute = 0, int second = 0, int microsecond = 0);
@ -132,10 +131,10 @@ namespace Time {
friend bool operator>(const DateTime &a, const DateTime &b) { return (a.m_timestamp > b.m_timestamp); }
friend bool operator>=(const DateTime &a, const DateTime &b) { return (a.m_timestamp >= b.m_timestamp); }
Sint64 GetTimestamp() const { return m_timestamp; }
int64_t GetTimestamp() const { return m_timestamp; }
private:
explicit DateTime(Sint64 tstamp) :
explicit DateTime(int64_t tstamp) :
m_timestamp(tstamp) {}
// The timestamp is the number of microseconds since the epoch (2001-01-01T00:00:00Z)
@ -157,7 +156,7 @@ namespace Time {
// because leap seconds are not predictable (they're introduced as necessary based on astronomical observations)
//
// (Incidentally, this is the way all integer timestamps work, at least all the ones I've ever seen)
Sint64 m_timestamp; // (units: microseconds; 0 means 2001-01-01T00:00:00Z)
int64_t m_timestamp; // (units: microseconds; 0 means 2001-01-01T00:00:00Z)
};
} // namespace Time