Back to index

lightning-sunbird  0.9+nobinonly
nsTime.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsTime_h__
00039 #define nsTime_h__
00040 
00041 #include "prtime.h"
00042 #include "nsInt64.h"
00043 #include "nscore.h"
00044 
00050 // If you ever decide that you need to add a non-inline method to this
00051 // class, be sure to change the class declaration to "class NS_BASE
00052 // nsTime".
00053 
00054 class nsTime : public nsInt64
00055 {
00056 public:
00060     nsTime(void) : nsInt64(PR_Now()) {
00061     }
00062 
00066     nsTime(const char* dateStr, PRBool defaultToGMT) {
00067         PRInt64 theTime;
00068         PRStatus status = PR_ParseTimeString(dateStr, defaultToGMT, &theTime);
00069         if (status == PR_SUCCESS)
00070             mValue = theTime;
00071         else
00072             mValue = LL_ZERO;
00073     }
00074 
00078     nsTime(const PRTime aTime) : nsInt64(aTime) {
00079     }
00080 
00084     nsTime(const nsInt64& aTime) : nsInt64(aTime) {
00085     }
00086 
00090     nsTime(const nsTime& aTime) : nsInt64(aTime.mValue) {
00091     }
00092 
00093     // ~nsTime(void) -- XXX destructor unnecessary
00094 
00098     const nsTime& operator =(const nsTime& aTime) {
00099         mValue = aTime.mValue;
00100         return *this;
00101     }
00102 
00106     operator PRTime(void) const {
00107         return mValue;
00108     }
00109 };
00110 
00114 inline const PRBool
00115 operator <(const nsTime& aTime1, const nsTime& aTime2) {
00116     return aTime1.mValue < aTime2.mValue;
00117 }
00118 
00122 inline const PRBool
00123 operator <=(const nsTime& aTime1, const nsTime& aTime2) {
00124     return aTime1.mValue <= aTime2.mValue;
00125 }
00126 
00130 inline const PRBool
00131 operator >(const nsTime& aTime1, const nsTime& aTime2) {
00132     return aTime1.mValue > aTime2.mValue;
00133 }
00134 
00138 inline const PRBool
00139 operator >=(const nsTime& aTime1, const nsTime& aTime2) {
00140     return aTime1.mValue >= aTime2.mValue;
00141 }
00142 
00143 #endif // nsTime_h__