SmartOS/Core/TimeSpan.h

44 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __TimeSpan_H__
#define __TimeSpan_H__
// 时间间隔
class TimeSpan
{
public:
TimeSpan(Int64 ms = 0);
TimeSpan(int hours, int minutes, int seconds);
TimeSpan(int days, int hours, int minutes, int seconds);
int Days() const;
int Hours() const;
int Minutes() const;
int Seconds() const;
int Ms() const;
int TotalDays() const;
int TotalHours() const;
int TotalMinutes() const;
int TotalSeconds() const;
Int64 TotalMs() const;
int CompareTo(const TimeSpan& value) const;
friend bool operator== (const TimeSpan& left, const TimeSpan& right);
friend bool operator!= (const TimeSpan& left, const TimeSpan& right);
friend bool operator> (const TimeSpan& left, const TimeSpan& right);
friend bool operator< (const TimeSpan& left, const TimeSpan& right);
friend bool operator>= (const TimeSpan& left, const TimeSpan& right);
friend bool operator<= (const TimeSpan& left, const TimeSpan& right);
String ToString() const;
void Show(bool newLine = false) const;
private:
int _Seconds;
int _Ms;
};
/*
分开存储秒数和毫秒数绝大多数时候只需要秒数进行运算大大减少了64位整数运算提升效率。
*/
#endif