1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 ** Class definitions for calendar time routines (ref: prtime.h)
42 #if defined(_RCTIME_H)
51 ** Class: RCTime (ref: prtime.h)
53 ** RCTimes are objects that are intended to be used to represent calendar
54 ** times. They maintain units internally as microseconds since the defined
55 ** epoch (midnight, January 1, 1970, GMT). Conversions to and from external
56 ** formats (PRExplodedTime) are available.
58 ** In general, NCTimes possess normal algebretic capabilities.
61 class PR_IMPLEMENT(RCTime
): public RCBase
64 typedef enum {now
} Current
;
66 RCTime(); /* leaves the object unitialized */
67 RCTime(Current
); /* initializes to current system time */
68 RCTime(const RCTime
&); /* copy constructor */
69 RCTime(const PRExplodedTime
&); /* construction from exploded representation */
73 /* assignment operators */
74 void operator=(const RCTime
&);
75 void operator=(const PRExplodedTime
&);
77 /* comparitive operators */
78 PRBool
operator<(const RCTime
&);
79 PRBool
operator>(const RCTime
&);
80 PRBool
operator<=(const RCTime
&);
81 PRBool
operator>=(const RCTime
&);
82 PRBool
operator==(const RCTime
&);
84 /* associative operators */
85 RCTime
operator+(const RCTime
&);
86 RCTime
operator-(const RCTime
&);
87 RCTime
& operator+=(const RCTime
&);
88 RCTime
& operator-=(const RCTime
&);
90 /* multiply and divide operators */
91 RCTime
operator/(PRUint64
);
92 RCTime
operator*(PRUint64
);
93 RCTime
& operator/=(PRUint64
);
94 RCTime
& operator*=(PRUint64
);
96 void Now(); /* assign current time to object */
103 RCTime(PRTime
); /* construct from raw PRTime */
104 void operator=(PRTime
); /* assign from raw PRTime */
105 operator PRTime() const; /* extract internal representation */
108 inline RCTime::RCTime(): RCBase() { }
110 inline void RCTime::Now() { gmt
= PR_Now(); }
111 inline RCTime::operator PRTime() const { return gmt
; }
113 inline void RCTime::operator=(PRTime his
) { gmt
= his
; }
114 inline void RCTime::operator=(const RCTime
& his
) { gmt
= his
.gmt
; }
116 inline PRBool
RCTime::operator<(const RCTime
& his
)
117 { return (gmt
< his
.gmt
) ? PR_TRUE
: PR_FALSE
; }
118 inline PRBool
RCTime::operator>(const RCTime
& his
)
119 { return (gmt
> his
.gmt
) ? PR_TRUE
: PR_FALSE
; }
120 inline PRBool
RCTime::operator<=(const RCTime
& his
)
121 { return (gmt
<= his
.gmt
) ? PR_TRUE
: PR_FALSE
; }
122 inline PRBool
RCTime::operator>=(const RCTime
& his
)
123 { return (gmt
>= his
.gmt
) ? PR_TRUE
: PR_FALSE
; }
124 inline PRBool
RCTime::operator==(const RCTime
& his
)
125 { return (gmt
== his
.gmt
) ? PR_TRUE
: PR_FALSE
; }
127 inline RCTime
& RCTime::operator+=(const RCTime
& his
)
128 { gmt
+= his
.gmt
; return *this; }
129 inline RCTime
& RCTime::operator-=(const RCTime
& his
)
130 { gmt
-= his
.gmt
; return *this; }
131 inline RCTime
& RCTime::operator/=(PRUint64 his
)
132 { gmt
/= his
; return *this; }
133 inline RCTime
& RCTime::operator*=(PRUint64 his
)
134 { gmt
*= his
; return *this; }
136 #endif /* defined(_RCTIME_H) */