OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
time.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Borland Class Library
3// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4//
5//
6//------------------------------------------------------------------------------
7
8#if !defined(OWL_TIME_H)
9#define OWL_TIME_H
10
11#include <owl/private/defs.h>
12#if defined(BI_HAS_PRAGMA_ONCE)
13# pragma once
14#endif
15
16#include <owl/date.h>
17#include <time.h>
19
20
21namespace owl {
22
23#include <owl/preclass.h>
24
25class _OWLCLASS ipstream;
26class _OWLCLASS opstream;
27
28class _OWLCLASS TFileTime;
29
30typedef unsigned HourTy;
31typedef unsigned MinuteTy;
32typedef unsigned SecondTy;
33typedef unsigned long ClockTy;
34
35static const unsigned long secFrom_Jan_1_1901_to_Jan_1_1970 = 2177452800UL;
36
37/// The TTime class encapsulates time functions and characteristics.
39 public:
40
41 friend TDate::TDate( const TTime & );
42
43 TTime(); // Current time
44 TTime(const TSystemTime & t); ///< from SYSTEMTIME
45 TTime(const TFileTime & t); ///< from FILETIME
46 TTime( ClockTy s ); // Seconds since Jan 1, 1901.
47 TTime( HourTy h, MinuteTy m, SecondTy s = 0 );
48 // Specified time and today's date
49 TTime( const TDate &, HourTy h=0, MinuteTy m=0, SecondTy s=0 );
50 // Given date and time
51
52 TSystemTime GetSystemTime() const;
53 TFileTime GetFileTime() const;
54
55 tstring AsString() const;
56 int CompareTo( const TTime & ) const;
57 unsigned Hash() const;
58 HourTy Hour() const; // hour: local time
59 HourTy HourGMT() const; // hour: GMT
60 int IsDST() const;
61 int IsValid() const;
62 TTime Max( const TTime & t ) const;
63 TTime Min( const TTime & t ) const;
64 MinuteTy Minute() const; // minute: local time
65 MinuteTy MinuteGMT() const; // minute: GMT
66 SecondTy Second() const; // second: local time or GMT
67 ClockTy Seconds() const;
68
69 // Write times:
70 friend _OWLCFUNC(tostream &) operator << ( tostream &, const TTime & );
71
72 // Read or write times on persistent streams
73 friend _OWLCFUNC(opstream &) operator << ( opstream & s, const TTime & d );
74 friend _OWLCFUNC(ipstream &) operator >> ( ipstream & s, TTime & d );
75
76 // Boolean operators.
77 int operator < ( const TTime & t ) const;
78 int operator <= ( const TTime & t ) const;
79 int operator > ( const TTime & t ) const;
80 int operator >= ( const TTime & t ) const;
81 int operator == ( const TTime & t ) const;
82 int operator != ( const TTime & t ) const;
83 int Between( const TTime & a, const TTime & b ) const;
84
85 // Add or subtract seconds.
86 friend _OWLFUNC(TTime) operator + ( const TTime & t, long s );
87 friend _OWLFUNC(TTime) operator + ( long s, const TTime & t );
88 friend _OWLFUNC(TTime) operator - ( const TTime & t, long s );
89 friend _OWLFUNC(TTime) operator - ( long s, const TTime & t );
90 void operator++();
91 void operator--();
92 void operator+=(long s);
93 void operator-=(long s);
94
95 // Static member functions:
96 static TTime BeginDST( unsigned year ); // Start of DST for given year.
97 static TTime EndDST( unsigned year ); // End of DST for given year.
98 static int PrintDate( int ); // Whether to include date when printing time
99
100protected:
101
102 static int AssertDate( const TDate & );
103 static const TDate RefDate; ///< The minimum valid date for TTime objects: January 1, 1901.
104 static const TDate MaxDate; ///< The maximum valid date for TTime objects.
105
106private:
107
108 ClockTy Sec; ///< Seconds since 1/1/1901.
109 static int PrintDateFlag; ///< True to print date along with time.
110
111 ClockTy LocalSecs() const;
112 static TTime BuildLocal( const TDate &, HourTy );
113
114};
115
116#include <owl/posclass.h>
117
118/// Constructs a TTime object with the given s (seconds since January 1, 1901).
120{
121 Sec = s;
122}
123
124/// Returns 1 if this TTime object contains a valid time, 0 otherwise.
125/// \todo Why not return bool?
126inline int TTime::IsValid() const
127{
128 return Sec > 0;
129}
130
131/// Returns seconds since January 1, 1901.
133{
134 return Sec;
135}
136
137/// Returns 1 if the target time is less than time t, 0 otherwise.
138inline int TTime::operator < ( const TTime& t ) const
139{
140 return Sec < t.Sec;
141}
142
143/// Returns 1 if the target time is less than or equal to time t, 0 otherwise.
144inline int TTime::operator <= ( const TTime& t ) const
145{
146 return Sec <= t.Sec;
147}
148
149/// Returns 1 if the target time is greater than time t, 0 otherwise.
150inline int TTime::operator > ( const TTime& t ) const
151{
152 return Sec > t.Sec;
153}
154
155/// Returns 1 if the target time is greater than or equal to time t, 0 otherwise.
156inline int TTime::operator >= ( const TTime& t ) const
157{
158 return Sec >= t.Sec;
159}
160
161/// Returns 1 if the target time is equal to time t, 0 otherwise.
162inline int TTime::operator == ( const TTime& t ) const
163{
164 return Sec == t.Sec;
165}
166
167/// Returns 1 if the target time is not equal to time t, 0 otherwise.
168inline int TTime::operator != ( const TTime& t ) const
169{
170 return Sec != t.Sec;
171}
172
173/// Returns 1 if the target date is between TTime a and TTime b, 0 otherwise.
174inline int TTime::Between( const TTime& a, const TTime& b ) const
175{
176 return *this >= a && *this <= b;
177}
178
179/// Adds s seconds to time t.
180inline TTime operator + ( const TTime& t, long s )
181{
182 return TTime(t.Sec+s);
183}
184
185/// Adds s seconds to time t.
186inline TTime operator + ( long s, const TTime& t )
187{
188 return TTime(t.Sec+s);
189}
190
191/// Performs subtraction, in seconds, between s and t.
192inline TTime operator - ( const TTime& t, long s )
193{
194 return TTime(t.Sec-s);
195}
196
197/// Performs subtraction, in seconds, between s and t.
198inline TTime operator - ( long s, const TTime& t )
199{
200 return TTime(t.Sec-s);
201}
202
203/// Increments the time by 1 second.
204inline void TTime::operator++()
205{
206 Sec += 1;
207}
208
209/// Decrements the time by 1 second.
210inline void TTime::operator--()
211{
212 Sec -= 1;
213}
214
215/// Adds s seconds to the time.
216inline void TTime::operator+=(long s)
217{
218 Sec += s;
219}
220
221/// Subtracts s seconds from the time.
222inline void TTime::operator-=(long s)
223{
224 Sec -= s;
225}
226
227inline unsigned HashValue( TTime & t )
228{
229 return t.Hash();
230}
231
232} // OWL namespace
233
234
235#endif // OWL_TIME_H
The TDate class represents a date.
Definition date.h:48
TFileTime is a class derived from the structure FILETIME.
Definition wsyscls.h:362
TSystemTime is a class derived from the structure SYSTEMTIME.
Definition wsyscls.h:420
The TTime class encapsulates time functions and characteristics.
Definition time.h:38
int Between(const TTime &a, const TTime &b) const
Returns 1 if the target date is between TTime a and TTime b, 0 otherwise.
Definition time.h:174
void operator++()
Increments the time by 1 second.
Definition time.h:204
int operator!=(const TTime &t) const
Returns 1 if the target time is not equal to time t, 0 otherwise.
Definition time.h:168
unsigned Hash() const
Hash function: Returns seconds since January 1, 1901.
Definition time.cpp:258
int operator<(const TTime &t) const
Returns 1 if the target time is less than time t, 0 otherwise.
Definition time.h:138
static const TDate MaxDate
The maximum valid date for TTime objects.
Definition time.h:104
int operator==(const TTime &t) const
Returns 1 if the target time is equal to time t, 0 otherwise.
Definition time.h:162
ClockTy Seconds() const
Returns seconds since January 1, 1901.
Definition time.h:132
int operator>=(const TTime &t) const
Returns 1 if the target time is greater than or equal to time t, 0 otherwise.
Definition time.h:156
int operator>(const TTime &t) const
Returns 1 if the target time is greater than time t, 0 otherwise.
Definition time.h:150
void operator-=(long s)
Subtracts s seconds from the time.
Definition time.h:222
TTime()
Construct TTime with current time (seconds since Jan 1, 1901).
Definition time.cpp:137
void operator--()
Decrements the time by 1 second.
Definition time.h:210
void operator+=(long s)
Adds s seconds to the time.
Definition time.h:216
int operator<=(const TTime &t) const
Returns 1 if the target time is less than or equal to time t, 0 otherwise.
Definition time.h:144
int IsValid() const
Returns 1 if this TTime object contains a valid time, 0 otherwise.
Definition time.h:126
static const TDate RefDate
The minimum valid date for TTime objects: January 1, 1901.
Definition time.h:103
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
Base class for writing streamable objects.
Definition objstrm.h:480
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned HourTy
Definition time.h:30
unsigned long ClockTy
Definition time.h:33
unsigned SecondTy
Definition time.h:32
TTime operator+(const TTime &t, long s)
Adds s seconds to time t.
Definition time.h:180
TTime operator-(const TTime &t, long s)
Performs subtraction, in seconds, between s and t.
Definition time.h:192
unsigned MinuteTy
Definition time.h:31
unsigned HashValue(TDate &d)
Definition date.h:318
std::string tstring
Definition defs.h:79
std::ostream tostream
Definition strmdefs.h:40
#define _OWLFUNC(p)
Definition defs.h:341
#define _OWLCFUNC(p)
Definition defs.h:342
#define _OWLCLASS
Definition defs.h:338