POCO C++库学习和分析 -- 日期与时间 (二)

2014-11-24 03:20:57 · 作者: · 浏览: 8
e() const;
/// Returns the timestamp expressed in time_t.
/// time_t base time is midnight, January 1, 1970.
/// Resolution is one second.

UtcTimeva l utcTime() const;
/// Returns the timestamp expressed in UTC-based
/// time. UTC base time is midnight, October 15, 1582.
/// Resolution is 100 nanoseconds.

Timeva l epochMicroseconds() const;
/// Returns the timestamp expressed in microseconds
/// since the Unix epoch, midnight, January 1, 1970.

TimeDiff elapsed() const;
/// Returns the time elapsed since the time denoted by
/// the timestamp. Equivalent to Timestamp() - *this.

bool isElapsed(TimeDiff interval) const;
/// Returns true iff the given interval has passed
/// since the time denoted by the timestamp.

static Timestamp fromEpochTime(std::time_t t);
/// Creates a timestamp from a std::time_t.

static Timestamp fromUtcTime(UtcTimeva l val);
/// Creates a timestamp from a UTC time value.

static Timeva l resolution();
/// Returns the resolution in units per second.
/// Since the timestamp has microsecond resolution,
/// the returned value is always 1000000.

private:
Timeva l _ts;
};

class Foundation_API Timestamp
{
public:
typedef Int64 Timeva l; /// monotonic UTC time value in microsecond resolution
typedef Int64 UtcTimeva l; /// monotonic UTC time value in 100 nanosecond resolution
typedef Int64 TimeDiff; /// difference between two timestamps in microseconds

Timestamp();
/// Creates a timestamp with the current time.

Timestamp(Timeva l tv);
/// Creates a timestamp from the given time value.

Timestamp(const Timestamp& other);
/// Copy constructor.

~Timestamp();

/// Destroys the timestamp

Timestamp& operator = (const Timestamp& other);
Timestamp& operator = (Timeva l tv);

void swap(Timestamp& timestamp);
/// Swaps the Timestamp with another one.

void update();
/// Updates the Timestamp with the current time.


bool operator == (const Timestamp& ts) const;
bool operator != (const Timestamp& ts) const;
bool operator > (const Timestamp& ts) const;
bool operator >= (const Timestamp& ts) const;
bool operator < (const Timestamp& ts) const;
bool operator <= (const Timestamp& ts) const;

Timestamp operator + (TimeDiff d) const;
Timestamp operator - (TimeDiff d) const;
TimeDiff operator - (const Timestamp& ts) const;
Timestamp& operator += (TimeDiff d);
Timestamp& operator -= (TimeDiff d);

std::time_t epochTime() const;
/// Returns the timestamp expressed in time_t.
/// time_t base time is midnight, January 1, 1970.
/// Resolution is one second.

UtcTimeva l utcTime() const;
/// Returns the timestamp expressed in UTC-based
/// time. UTC base time is midnight, October 15, 1582.
/// Resolution is 100 nanoseconds.

Timeva l epochMicroseconds() const;
/// Returns the timestamp expressed in microseconds
/// since the Unix epoch, midnight, January 1, 1970.

TimeDiff elapsed() const;
/// Returns the time elapsed since the time denoted by
/// the timestamp. Equivalent to Timestamp() - *this.

bool isElapsed(TimeDiff interval) const;
/// Returns true iff the given interval has passed
/// since the time denoted by the timestamp.

static Timestamp fromEpochTime(std::time_t t);
/// Creates a timestamp from a std::time_t.

static Timestamp fromUtcTime