|
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() { gmt = PR_Now(); } |
|
79 inline RCTime::operator PRTime() const { return gmt; } |
|
80 |
|
81 inline void RCTime::operator=(PRTime his) { gmt = his; } |
|
82 inline void RCTime::operator=(const RCTime& his) { gmt = his.gmt; } |
|
83 |
|
84 inline PRBool RCTime::operator<(const RCTime& his) |
|
85 { return (gmt < his.gmt) ? PR_TRUE : PR_FALSE; } |
|
86 inline PRBool RCTime::operator>(const RCTime& his) |
|
87 { return (gmt > his.gmt) ? PR_TRUE : PR_FALSE; } |
|
88 inline PRBool RCTime::operator<=(const RCTime& his) |
|
89 { return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE; } |
|
90 inline PRBool RCTime::operator>=(const RCTime& his) |
|
91 { return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE; } |
|
92 inline PRBool RCTime::operator==(const RCTime& his) |
|
93 { return (gmt == his.gmt) ? PR_TRUE : PR_FALSE; } |
|
94 |
|
95 inline RCTime& RCTime::operator+=(const RCTime& his) |
|
96 { gmt += his.gmt; return *this; } |
|
97 inline RCTime& RCTime::operator-=(const RCTime& his) |
|
98 { gmt -= his.gmt; return *this; } |
|
99 inline RCTime& RCTime::operator/=(PRUint64 his) |
|
100 { gmt /= his; return *this; } |
|
101 inline RCTime& RCTime::operator*=(PRUint64 his) |
|
102 { gmt *= his; return *this; } |
|
103 |
|
104 #endif /* defined(_RCTIME_H) */ |
|
105 |
|
106 /* RCTime.h */ |