-
Notifications
You must be signed in to change notification settings - Fork 0
Time class
Colin Girling edited this page Feb 19, 2017
·
18 revisions
typedef uint32_t size_type;
typedef int32_t diff_type;
typedef uint16_t millisecond_type;
typedef uint8_t second_type;
typedef uint8_t minute_type;
typedef uint8_t hour_type;
MILLISECONDS_PER_SECOND = 1000
SECONDS_PER_MINUTE = 60
MINUTES_PER_HOUR = 60
HOURS_PER_DAY = 24
MAX_MILLISECONDS = 999
MAX_SECONDS = 59
MAX_MINUTES = 59
MAX_HOURS = 23
MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE
MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * MINUTES_PER_HOUR
MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * HOURS_PER_DAY
SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR
SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY
MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY
Time() throw(); // default to 0:0:0:0
Time(hour_type hours, // 0..23
minute_type minutes, // 0..59
second_type seconds, // 0..59
millisecond_type milliseconds) throw(); // 0..999
Time(Time const& time) throw(); // Copy time from source time.
Time& operator =(Time const& time) throw();
bool operator <(Time const& other) const throw();
bool operator <=(Time const& other) const throw();
bool operator >(Time const& other) const throw();
bool operator >=(Time const& other) const throw();
bool operator ==(Time const& other) const throw();
bool operator !=(Time const& other) const throw();
Time& operator +=(uint32_t milliseconds) throw();
Time& operator -=(uint32_t milliseconds) throw();
Time operator +(size_type milliseconds) const throw();
Time operator -(size_type milliseconds) const throw();
diff_type operator -(Time const& other) const throw();
Time operator ++() throw(); // Prefix - add a millisecond.
Time operator ++(int) throw(); // Postfix - add a millisecond.
Time operator --() throw(); // Prefix - subtract a millisecond.
Time operator --(int) throw(); // Postfix - subtract a millisecond.
static void SplitMilliseconds(size_type& hours,
size_type& minutes,
size_type& seconds,
size_type& milliseconds) throw();
static size_type ToMilliseconds(size_type hours,
size_type minutes,
size_type seconds,
size_type milliseconds) throw();
#Member functions
millisecond_type GetMilliseconds() const throw();
void SetMilliseconds(millisecond_type milliseconds) throw();
second_type GetSeconds() const throw();
void SetSeconds(second_type seconds) throw();
minute_type GetMinutes() const throw();
void SetMinutes(minute_type minutes) throw();
hour_type GetHours() const throw();
void SetHours(hour_type hours) throw();
void SetStart() throw(); // Reset to 0:0:0:0
void SetEnd() throw(); // Reset to 23:59:59:999
size_type GetAsMilliseconds() const throw(); // Convert time to milliseconds.
void SetFromMilliseconds(size_type milliseconds) throw(); // Convert milliseconds to time.
size_type GetDifferenceInMilliseconds(Time const& other) const throw();
// Add milliseconds up to 23:59:59:999.
void AddMilliseconds(size_type milliseconds) throw();
// Add milliseconds up to 23:59:59:999 and return any overflow.
void AddMilliseconds(size_type milliseconds, size_type& overflow) throw();
// Subtract milliseconds to 0:0:0:0.
void SubtractMilliseconds(size_type milliseconds) throw();
// Subtract milliseconds to 0:0:0:0 and return any underflow.
void SubtractMilliseconds(size_type milliseconds, size_type& underflow) throw();
// Get the time as a 32-bit value for conveniently serializing the time.
uint32_t GetTime() const throw();
// Set the time from a 32-bit value for conveniently serializing the time.
void SetTime(uint32_t time) throw();
void SetTime(Time const& time) throw();
void SetTime(hour_type hours,
minute_type minutes,
second_type seconds,
millisecond_type milliseconds) throw();
bool IsLess(Time const& other) const throw();
bool IsLessEqual(Time const& other) const throw();
bool IsGreater(Time const& other) const throw();
bool IsGreaterEqual(Time const& other) const throw();
bool IsEqual(Time const& other) const throw();
bool IsNotEqual(Time const& other) const throw();
// Return -1 when this time is less than other time, 0 when equal or
// 1 when this time is greater than other time.
int Compare(Time const& other) const throw();