home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWTIME_H__
- #define __RWTIME_H__
- pragma push_align_members(64);
-
- /*
- * Declarations for class RWTime.
- *
- * $Header: E:/vcs/rw/rwtime.h_v 1.6 04 Mar 1992 10:21:36 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave Software, Inc.
- * P.O. Box 2328
- * Corvallis, OR 97339
- * Voice: (503) 754-3010 FAX: (503) 757-6650
- *
- * Copyright (C) 1989, 1990, 1991. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/rw/rwtime.h_v $
- *
- * Rev 1.6 04 Mar 1992 10:21:36 KEFFER
- * Instance manager used in multi-thread situation.
- *
- * Rev 1.4 13 Nov 1991 11:10:26 keffer
- * Static variables maintained by a manager for multi-thread version
- *
- * Rev 1.3 29 Oct 1991 13:57:04 keffer
- * Added 24hour clock print option.
- *
- * Rev 1.2 28 Oct 1991 09:08:22 keffer
- * Changed inclusions to <rw/xxx.h>
- *
- * Rev 1.1 22 Aug 1991 10:20:16 keffer
- * Simplified construction of times by defining m.f. buildFrom()
- *
- * Rev 1.0 28 Jul 1991 08:16:44 keffer
- * Tools.h++ V4.0.5 PVCS baseline version
- *
- */
-
- #include "rw/tooldefs.h"
- #include "rw/rwdate.h"
- #include "rw/procinit.h" /* Uses instance data */
- STARTWRAP
- #include <time.h> /* System time management. */
- ENDWRAP
-
- class RWExport RWCString;
-
- typedef unsigned hourTy;
- typedef unsigned minuteTy;
- typedef unsigned secondTy;
- typedef unsigned long clockTy;
- static const unsigned long secFrom_Jan_1_1901_to_Jan_1_1970 = 2177452800L;
-
- class RWExport RWTime {
- friend RWDate::RWDate(const RWTime&);
- private:
- clockTy sec; // Seconds since 1/1/1901.
- #ifndef RW_MULTI_THREAD
- /* If not compiling for an MT situation, then use static data--- */
- static RWBoolean printDateFlag; // True to print date along with time.
- static RWBoolean milTimeFlag; // True to use 24-hour clock
- #endif
- protected:
- static RWBoolean assertDate(const RWDate&);
- void buildFrom(const RWDate&, hourTy, minuteTy, secondTy);
- static const RWDate refDate;
- static const RWDate maxDate;
- private:
- clockTy localSecs() const;
- static RWTime buildLocal(const RWDate&, hourTy);
- public:
-
- RWTime(); // Current time
- RWTime(clockTy s) {sec = s;} // Seconds since Jan 1, 1901.
- RWTime(hourTy h, minuteTy m, secondTy s = 0); // Specified time and today's date
- RWTime(const RWDate&, hourTy h=0, minuteTy m=0, secondTy s=0); // Given date and time
-
- RWCString asString() const;
- unsigned binaryStoreSize() const {return sizeof(clockTy);}
- int compareTo(const RWTime*) const;
- unsigned hash() const;
- hourTy hour() const; // hour: local time
- hourTy hourGMT() const; // hour: GMT
- RWBoolean isDST() const;
- RWBoolean isValid() const {return sec>0;}
- RWTime max(const RWTime& t) const;
- RWTime min(const RWTime& t) const;
- minuteTy minute() const; // minute: local time
- minuteTy minuteGMT() const; // minute: GMT
- void restoreFrom(RWFile&);
- void restoreFrom(RWvistream&);
- void saveOn(RWFile&) const;
- void saveOn(RWvostream&) const;
- secondTy second() const; // second: local time or GMT
- clockTy seconds() const {return sec;}
- friend ostream& operator<<(ostream&, const RWTime&);
-
- // Boolean operators.
- RWBoolean operator<(const RWTime& t) const { return sec < t.sec; }
- RWBoolean operator<=(const RWTime& t) const { return sec <= t.sec; }
- RWBoolean operator>(const RWTime& t) const { return sec > t.sec; }
- RWBoolean operator>=(const RWTime& t) const { return sec >= t.sec; }
- RWBoolean operator==(const RWTime& t) const { return sec == t.sec; }
- RWBoolean operator!=(const RWTime& t) const { return sec != t.sec; }
- RWBoolean between(const RWTime& a, const RWTime& b) const
- { return *this >= a && *this <= b;}
-
- // Add or subtract seconds.
- friend RWTime operator+(const RWTime& t, long s)
- { return RWTime(t.sec+s); }
- friend RWTime operator+(long s, const RWTime& t)
- { return RWTime(t.sec+s); }
- friend RWTime operator-(const RWTime& t, long s)
- { return RWTime(t.sec-s); }
- friend RWTime operator-(long s, const RWTime& t)
- { return RWTime(t.sec-s); }
- void operator++() { ++sec; }
- void operator--() { --sec; }
- #ifdef CPPV21
- void operator++(int) { sec++; }
- void operator--(int) { sec--; }
- #endif
- void operator+=(long s) { sec += s; }
- void operator-=(long s) { sec -= s; }
-
- // Static member functions:
- static RWTime beginDST(unsigned year); // Start of DST for given year.
- static RWTime endDST(unsigned year); // End of DST for given year.
- static RWBoolean printDate(RWBoolean); // Whether to include date when printing time
- static RWBoolean milTime(RWBoolean); // Whether to use 24-hour clk
- #ifdef RW_MULTI_THREAD
- // Just declarations --- static data must be retrieved from the instance manager.
- static RWBoolean getPrintDateFlag();
- static RWBoolean getMilTimeFlag();
- #else
- static RWBoolean getPrintDateFlag() {return printDateFlag;}
- static RWBoolean getMilTimeFlag() {return milTimeFlag;}
- #endif
- };
-
- inline RWTime::RWTime(const RWDate& d, hourTy h, minuteTy m, secondTy s)
- { buildFrom(d,h,m,s); }
-
- pragma pop_align_members();
- #endif /* __RWTIME_H__ */
-