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
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.
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 ***** */
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
54 class nsTime
: public nsInt64
58 * Construct the current time.
60 nsTime(void) : nsInt64(PR_Now()) {
64 * Construct the time from a string.
66 nsTime(const char* dateStr
, PRBool defaultToGMT
) {
68 PRStatus status
= PR_ParseTimeString(dateStr
, defaultToGMT
, &theTime
);
69 if (status
== PR_SUCCESS
)
76 * Construct a time from a PRTime.
78 nsTime(const PRTime aTime
) : nsInt64(aTime
) {
82 * Construct a time from a 64-bit value.
84 nsTime(const nsInt64
& aTime
) : nsInt64(aTime
) {
88 * Construct a time from another time.
90 nsTime(const nsTime
& aTime
) : nsInt64(aTime
.mValue
) {
93 // ~nsTime(void) -- XXX destructor unnecessary
96 * Assign one time to another.
98 const nsTime
& operator =(const nsTime
& aTime
) {
99 mValue
= aTime
.mValue
;
104 * Convert a nsTime object to a PRTime
106 operator PRTime(void) const {
112 * Determine if one time is strictly less than another
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
123 operator <=(const nsTime
& aTime1
, const nsTime
& aTime2
) {
124 return aTime1
.mValue
<= aTime2
.mValue
;
128 * Determine if one time is strictly greater than another
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
139 operator >=(const nsTime
& aTime1
, const nsTime
& aTime2
) {
140 return aTime1
.mValue
>= aTime2
.mValue
;