File: Time_.h

package info (click to toggle)
ivtools 1.2.11a2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,364 kB
  • sloc: cpp: 174,988; ansic: 12,717; xml: 5,359; perl: 2,164; makefile: 831; sh: 326
file content (150 lines) | stat: -rw-r--r-- 4,026 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

/* Time.h -- declarations for class Time 
	THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
	"UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
	AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
	CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
	PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
	RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.

Author:
	K. E. Gorlen
	Computer Systems Laboratory, DCRT
	National Institutes of Health
	Bethesda, MD 20892
*/
/* Log:	Time.h,v 
 * Revision 3.11  92/07/26  14:33:59  sandy
 * include directive in form '#include <nihcl/foo.h>'
 * 
 * Revision 3.10  91/02/18  21:08:49  kgorlen
 * Release for 3rd printing of 1st edition.
 * 
 * Revision 3.1  90/12/22  08:58:38  kgorlen
 * Change NESTED_TYPES to NO_NESTED_TYPES.
 * 
 * Revision 3.0  90/05/20  00:21:46  kgorlen
 * Release for 1st edition.
 * 
*/

#ifndef	TIME_H
#define	TIME_H


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_TIME_H
#if defined(__APPLE__)
#include <time.h>
#else
#include_next <time.h>
#endif
#endif

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif

#if defined(SYSV) && ! defined(hpux)

#define TIME_ZONE timezone
#define DST_OBSERVED daylight
#define BASE_CLASSES BASE::desc()
#define MEMBER_CLASSES
#define VIRTUAL_BASE_CLASSES Object::desc()

#endif

#if defined(linux) || defined(__sun) || defined(__alpha) || defined(__CYGWIN__)
  #if defined(__DECCXX) || (defined(__sun) && !defined(__svr4__))
    extern "C" {
    int gettimeofday(struct timeval *tp, struct timezone *tzp);
     }
  #endif
#endif 

// END of edits


/*
  Modified by Vectaport, Inc.
*/

#include <OS/types.h>
#if !defined(__APPLE_)
#include <iostream.h>
#else
#include <iosfwd>
#include <iostream>
#endif

#define NO_NESTED_TYPES 1

class Date;

#ifdef NO_NESTED_TYPES
typedef unsigned short hourTy;
typedef unsigned short minuteTy;
typedef unsigned short secondTy;
typedef unsigned long clockTy;
#endif

using std::cout;

class Time {

public:			// type definitions
#ifndef NO_NESTED_TYPES
	typedef unsigned short hourTy;
	typedef unsigned short minuteTy;
	typedef unsigned short secondTy;
	typedef unsigned long clockTy;
#endif
private:
	clockTy sec;			/* seconds since 1/1/1901 */
	boolean isDST() const;
	Time localTime() const;
private:		// static member functions
	static Time localTime(const Date& date, hourTy h=0, minuteTy m=0, secondTy s=0);
	static Time beginDST(unsigned year);
	static Time endDST(unsigned year);
public:
	Time();				// current time 
	Time(clockTy s)			{ sec = s; }
	Time(hourTy h, minuteTy m, secondTy s =0, boolean dst =false);
	Time(const Date&, hourTy h =0, minuteTy m =0, secondTy s=0, boolean dst =false);
	Date date() const;
	boolean operator<(const Time& t) const	{ return sec < t.sec; }
	boolean operator<=(const Time& t) const	{ return sec <= t.sec; }
	boolean operator>(const Time& t) const	{ return sec > t.sec; }
	boolean operator>=(const Time& t) const	{ return sec >= t.sec; }
	boolean operator==(const Time& t) const	{ return sec == t.sec; }
	boolean operator!=(const Time& t) const	{ return sec != t.sec; }
	friend Time operator+(const Time& t, long s)	{ return Time(t.sec+s); }
	friend Time operator+(long s, const Time& t)	{ return Time(t.sec+s); }
	long operator-(const Time& t) const	{ return sec - t.sec; }
	Time operator-(long s) const	{ return Time(sec-s); }
	void operator+=(long s)		{ sec += s; }
	void operator-=(long s)		{ sec -= s; }
	boolean between(const Time& a, const Time& b) const;
	hourTy hour() const;		// hour in local time 
	hourTy hourGMT() const;		// hour in GMT 
	minuteTy minute() const;	// minute in local time 
	minuteTy minuteGMT() const;	// minute in GMT 
	secondTy second() const;	// second in local time or GMT 
	clockTy	seconds() const		{ return sec; }

#undef min
#undef max

	Time max(const Time&) const;
	Time min(const Time&) const;
	virtual void printOn(ostream& strm =cout) const;

	friend ostream& operator << (ostream& s, const Time&);
};

#endif /* TIMEH */