| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
/* |
| 7 |
** Class definitions for calendar time routines (ref: prtime.h) |
| 8 |
*/ |
| 9 |
|
| 10 |
#if defined(_RCTIME_H) |
| 11 |
#else |
| 12 |
#define _RCTIME_H |
| 13 |
|
| 14 |
#include "rcbase.h" |
| 15 |
|
| 16 |
#include <prtime.h> |
| 17 |
|
| 18 |
/* |
| 19 |
** Class: RCTime (ref: prtime.h) |
| 20 |
** |
| 21 |
** RCTimes are objects that are intended to be used to represent calendar |
| 22 |
** times. They maintain units internally as microseconds since the defined |
| 23 |
** epoch (midnight, January 1, 1970, GMT). Conversions to and from external |
| 24 |
** formats (PRExplodedTime) are available. |
| 25 |
** |
| 26 |
** In general, NCTimes possess normal algebretic capabilities. |
| 27 |
*/ |
| 28 |
|
| 29 |
class PR_IMPLEMENT(RCTime): public RCBase |
| 30 |
{ |
| 31 |
public: |
| 32 |
typedef enum {now} Current; |
| 33 |
|
| 34 |
RCTime(); /* leaves the object unitialized */ |
| 35 |
RCTime(Current); /* initializes to current system time */ |
| 36 |
RCTime(const RCTime&); /* copy constructor */ |
| 37 |
RCTime(const PRExplodedTime&); /* construction from exploded representation */ |
| 38 |
|
| 39 |
virtual ~RCTime(); |
| 40 |
|
| 41 |
/* assignment operators */ |
| 42 |
void operator=(const RCTime&); |
| 43 |
void operator=(const PRExplodedTime&); |
| 44 |
|
| 45 |
/* comparitive operators */ |
| 46 |
PRBool operator<(const RCTime&); |
| 47 |
PRBool operator>(const RCTime&); |
| 48 |
PRBool operator<=(const RCTime&); |
| 49 |
PRBool operator>=(const RCTime&); |
| 50 |
PRBool operator==(const RCTime&); |
| 51 |
|
| 52 |
/* associative operators */ |
| 53 |
RCTime operator+(const RCTime&); |
| 54 |
RCTime operator-(const RCTime&); |
| 55 |
RCTime& operator+=(const RCTime&); |
| 56 |
RCTime& operator-=(const RCTime&); |
| 57 |
|
| 58 |
/* multiply and divide operators */ |
| 59 |
RCTime operator/(PRUint64); |
| 60 |
RCTime operator*(PRUint64); |
| 61 |
RCTime& operator/=(PRUint64); |
| 62 |
RCTime& operator*=(PRUint64); |
| 63 |
|
| 64 |
void Now(); /* assign current time to object */ |
| 65 |
|
| 66 |
private: |
| 67 |
PRTime gmt; |
| 68 |
|
| 69 |
public: |
| 70 |
|
| 71 |
RCTime(PRTime); /* construct from raw PRTime */ |
| 72 |
void operator=(PRTime); /* assign from raw PRTime */ |
| 73 |
operator PRTime() const; /* extract internal representation */ |
| 74 |
}; /* RCTime */ |
| 75 |
|
| 76 |
inline RCTime::RCTime(): RCBase() { } |
| 77 |
|
| 78 |
inline void RCTime::Now() { |
| 79 |
gmt = PR_Now(); |
| 80 |
} |
| 81 |
inline RCTime::operator PRTime() const { |
| 82 |
return gmt; |
| 83 |
} |
| 84 |
|
| 85 |
inline void RCTime::operator=(PRTime his) { |
| 86 |
gmt = his; |
| 87 |
} |
| 88 |
inline void RCTime::operator=(const RCTime& his) { |
| 89 |
gmt = his.gmt; |
| 90 |
} |
| 91 |
|
| 92 |
inline PRBool RCTime::operator<(const RCTime& his) |
| 93 |
{ |
| 94 |
return (gmt < his.gmt) ? PR_TRUE : PR_FALSE; |
| 95 |
} |
| 96 |
inline PRBool RCTime::operator>(const RCTime& his) |
| 97 |
{ |
| 98 |
return (gmt > his.gmt) ? PR_TRUE : PR_FALSE; |
| 99 |
} |
| 100 |
inline PRBool RCTime::operator<=(const RCTime& his) |
| 101 |
{ |
| 102 |
return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE; |
| 103 |
} |
| 104 |
inline PRBool RCTime::operator>=(const RCTime& his) |
| 105 |
{ |
| 106 |
return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE; |
| 107 |
} |
| 108 |
inline PRBool RCTime::operator==(const RCTime& his) |
| 109 |
{ |
| 110 |
return (gmt == his.gmt) ? PR_TRUE : PR_FALSE; |
| 111 |
} |
| 112 |
|
| 113 |
inline RCTime& RCTime::operator+=(const RCTime& his) |
| 114 |
{ |
| 115 |
gmt += his.gmt; |
| 116 |
return *this; |
| 117 |
} |
| 118 |
inline RCTime& RCTime::operator-=(const RCTime& his) |
| 119 |
{ |
| 120 |
gmt -= his.gmt; |
| 121 |
return *this; |
| 122 |
} |
| 123 |
inline RCTime& RCTime::operator/=(PRUint64 his) |
| 124 |
{ |
| 125 |
gmt /= his; |
| 126 |
return *this; |
| 127 |
} |
| 128 |
inline RCTime& RCTime::operator*=(PRUint64 his) |
| 129 |
{ |
| 130 |
gmt *= his; |
| 131 |
return *this; |
| 132 |
} |
| 133 |
|
| 134 |
#endif /* defined(_RCTIME_H) */ |
| 135 |
|
| 136 |
/* RCTime.h */ |