1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
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/
|
---|
9 | *
|
---|
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
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is mozilla.org code.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
26 | * or 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.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef nsTime_h__
|
---|
39 | #define nsTime_h__
|
---|
40 |
|
---|
41 | #include "prtime.h"
|
---|
42 | #include "nsInt64.h"
|
---|
43 | #include "nscore.h"
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * This class encapsulates full 64-bit time functionality and
|
---|
47 | * provides simple arithmetic and conversion operations.
|
---|
48 | */
|
---|
49 |
|
---|
50 | // If you ever decide that you need to add a non-inline method to this
|
---|
51 | // class, be sure to change the class declaration to "class NS_BASE
|
---|
52 | // nsTime".
|
---|
53 |
|
---|
54 | class nsTime : public nsInt64
|
---|
55 | {
|
---|
56 | public:
|
---|
57 | /**
|
---|
58 | * Construct the current time.
|
---|
59 | */
|
---|
60 | nsTime(void) : nsInt64(PR_Now()) {
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Construct the time from a string.
|
---|
65 | */
|
---|
66 | nsTime(const char* dateStr, PRBool defaultToGMT) {
|
---|
67 | PRInt64 theTime;
|
---|
68 | PRStatus status = PR_ParseTimeString(dateStr, defaultToGMT, &theTime);
|
---|
69 | if (status == PR_SUCCESS)
|
---|
70 | mValue = theTime;
|
---|
71 | else
|
---|
72 | mValue = LL_ZERO;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Construct a time from a PRTime.
|
---|
77 | */
|
---|
78 | nsTime(const PRTime aTime) : nsInt64(aTime) {
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Construct a time from a 64-bit value.
|
---|
83 | */
|
---|
84 | nsTime(const nsInt64& aTime) : nsInt64(aTime) {
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Construct a time from another time.
|
---|
89 | */
|
---|
90 | nsTime(const nsTime& aTime) : nsInt64(aTime.mValue) {
|
---|
91 | }
|
---|
92 |
|
---|
93 | // ~nsTime(void) -- XXX destructor unnecessary
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Assign one time to another.
|
---|
97 | */
|
---|
98 | const nsTime& operator =(const nsTime& aTime) {
|
---|
99 | mValue = aTime.mValue;
|
---|
100 | return *this;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Convert a nsTime object to a PRTime
|
---|
105 | */
|
---|
106 | operator PRTime(void) const {
|
---|
107 | return mValue;
|
---|
108 | }
|
---|
109 | };
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Determine if one time is strictly less than another
|
---|
113 | */
|
---|
114 | inline const PRBool
|
---|
115 | operator <(const nsTime& aTime1, const nsTime& aTime2) {
|
---|
116 | return aTime1.mValue < aTime2.mValue;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Determine if one time is less than or equal to another
|
---|
121 | */
|
---|
122 | inline const PRBool
|
---|
123 | operator <=(const nsTime& aTime1, const nsTime& aTime2) {
|
---|
124 | return aTime1.mValue <= aTime2.mValue;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Determine if one time is strictly greater than another
|
---|
129 | */
|
---|
130 | inline const PRBool
|
---|
131 | operator >(const nsTime& aTime1, const nsTime& aTime2) {
|
---|
132 | return aTime1.mValue > aTime2.mValue;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Determine if one time is greater than or equal to another
|
---|
137 | */
|
---|
138 | inline const PRBool
|
---|
139 | operator >=(const nsTime& aTime1, const nsTime& aTime2) {
|
---|
140 | return aTime1.mValue >= aTime2.mValue;
|
---|
141 | }
|
---|
142 |
|
---|
143 | #endif // nsTime_h__
|
---|