michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** Class definitions for calendar time routines (ref: prtime.h) michael@0: */ michael@0: michael@0: #if defined(_RCTIME_H) michael@0: #else michael@0: #define _RCTIME_H michael@0: michael@0: #include "rcbase.h" michael@0: michael@0: #include michael@0: michael@0: /* michael@0: ** Class: RCTime (ref: prtime.h) michael@0: ** michael@0: ** RCTimes are objects that are intended to be used to represent calendar michael@0: ** times. They maintain units internally as microseconds since the defined michael@0: ** epoch (midnight, January 1, 1970, GMT). Conversions to and from external michael@0: ** formats (PRExplodedTime) are available. michael@0: ** michael@0: ** In general, NCTimes possess normal algebretic capabilities. michael@0: */ michael@0: michael@0: class PR_IMPLEMENT(RCTime): public RCBase michael@0: { michael@0: public: michael@0: typedef enum {now} Current; michael@0: michael@0: RCTime(); /* leaves the object unitialized */ michael@0: RCTime(Current); /* initializes to current system time */ michael@0: RCTime(const RCTime&); /* copy constructor */ michael@0: RCTime(const PRExplodedTime&); /* construction from exploded representation */ michael@0: michael@0: virtual ~RCTime(); michael@0: michael@0: /* assignment operators */ michael@0: void operator=(const RCTime&); michael@0: void operator=(const PRExplodedTime&); michael@0: michael@0: /* comparitive operators */ michael@0: PRBool operator<(const RCTime&); michael@0: PRBool operator>(const RCTime&); michael@0: PRBool operator<=(const RCTime&); michael@0: PRBool operator>=(const RCTime&); michael@0: PRBool operator==(const RCTime&); michael@0: michael@0: /* associative operators */ michael@0: RCTime operator+(const RCTime&); michael@0: RCTime operator-(const RCTime&); michael@0: RCTime& operator+=(const RCTime&); michael@0: RCTime& operator-=(const RCTime&); michael@0: michael@0: /* multiply and divide operators */ michael@0: RCTime operator/(PRUint64); michael@0: RCTime operator*(PRUint64); michael@0: RCTime& operator/=(PRUint64); michael@0: RCTime& operator*=(PRUint64); michael@0: michael@0: void Now(); /* assign current time to object */ michael@0: michael@0: private: michael@0: PRTime gmt; michael@0: michael@0: public: michael@0: michael@0: RCTime(PRTime); /* construct from raw PRTime */ michael@0: void operator=(PRTime); /* assign from raw PRTime */ michael@0: operator PRTime() const; /* extract internal representation */ michael@0: }; /* RCTime */ michael@0: michael@0: inline RCTime::RCTime(): RCBase() { } michael@0: michael@0: inline void RCTime::Now() { gmt = PR_Now(); } michael@0: inline RCTime::operator PRTime() const { return gmt; } michael@0: michael@0: inline void RCTime::operator=(PRTime his) { gmt = his; } michael@0: inline void RCTime::operator=(const RCTime& his) { gmt = his.gmt; } michael@0: michael@0: inline PRBool RCTime::operator<(const RCTime& his) michael@0: { return (gmt < his.gmt) ? PR_TRUE : PR_FALSE; } michael@0: inline PRBool RCTime::operator>(const RCTime& his) michael@0: { return (gmt > his.gmt) ? PR_TRUE : PR_FALSE; } michael@0: inline PRBool RCTime::operator<=(const RCTime& his) michael@0: { return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE; } michael@0: inline PRBool RCTime::operator>=(const RCTime& his) michael@0: { return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE; } michael@0: inline PRBool RCTime::operator==(const RCTime& his) michael@0: { return (gmt == his.gmt) ? PR_TRUE : PR_FALSE; } michael@0: michael@0: inline RCTime& RCTime::operator+=(const RCTime& his) michael@0: { gmt += his.gmt; return *this; } michael@0: inline RCTime& RCTime::operator-=(const RCTime& his) michael@0: { gmt -= his.gmt; return *this; } michael@0: inline RCTime& RCTime::operator/=(PRUint64 his) michael@0: { gmt /= his; return *this; } michael@0: inline RCTime& RCTime::operator*=(PRUint64 his) michael@0: { gmt *= his; return *this; } michael@0: michael@0: #endif /* defined(_RCTIME_H) */ michael@0: michael@0: /* RCTime.h */