Back out due to mochiserver breakage. (no_r=me)
[mozilla-central.git] / xpcom / ds / nsTime.h
blobf5c3a0ab98040f64732479dcf2c82f3df2e911f1
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
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
13 * License.
15 * The Original Code is mozilla.org code.
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.
22 * Contributor(s):
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsTime_h__
39 #define nsTime_h__
41 #include "prtime.h"
42 #include "nsInt64.h"
43 #include "nscore.h"
45 /**
46 * This class encapsulates full 64-bit time functionality and
47 * provides simple arithmetic and conversion operations.
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".
54 class nsTime : public nsInt64
56 public:
57 /**
58 * Construct the current time.
60 nsTime(void) : nsInt64(PR_Now()) {
63 /**
64 * Construct the time from a string.
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;
75 /**
76 * Construct a time from a PRTime.
78 nsTime(const PRTime aTime) : nsInt64(aTime) {
81 /**
82 * Construct a time from a 64-bit value.
84 nsTime(const nsInt64& aTime) : nsInt64(aTime) {
87 /**
88 * Construct a time from another time.
90 nsTime(const nsTime& aTime) : nsInt64(aTime.mValue) {
93 // ~nsTime(void) -- XXX destructor unnecessary
95 /**
96 * Assign one time to another.
98 const nsTime& operator =(const nsTime& aTime) {
99 mValue = aTime.mValue;
100 return *this;
104 * Convert a nsTime object to a PRTime
106 operator PRTime(void) const {
107 return mValue;
112 * Determine if one time is strictly less than another
114 inline const PRBool
115 operator <(const nsTime& aTime1, const nsTime& aTime2) {
116 return aTime1.mValue < aTime2.mValue;
120 * Determine if one time is less than or equal to another
122 inline const PRBool
123 operator <=(const nsTime& aTime1, const nsTime& aTime2) {
124 return aTime1.mValue <= aTime2.mValue;
128 * Determine if one time is strictly greater than another
130 inline const PRBool
131 operator >(const nsTime& aTime1, const nsTime& aTime2) {
132 return aTime1.mValue > aTime2.mValue;
136 * Determine if one time is greater than or equal to another
138 inline const PRBool
139 operator >=(const nsTime& aTime1, const nsTime& aTime2) {
140 return aTime1.mValue >= aTime2.mValue;
143 #endif // nsTime_h__