Panda3D
httpDate.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file httpDate.I
10  * @author drose
11  * @date 2003-01-28
12  */
13 
14 /**
15  *
16  */
17 INLINE HTTPDate::
18 HTTPDate() : _time(-1) {
19 }
20 
21 /**
22  *
23  */
24 INLINE HTTPDate::
25 HTTPDate(time_t time) : _time(time) {
26 }
27 
28 /**
29  *
30  */
31 INLINE HTTPDate::
32 HTTPDate(const HTTPDate &copy) : _time(copy._time) {
33 }
34 
35 /**
36  *
37  */
38 INLINE void HTTPDate::
39 operator = (const HTTPDate &copy) {
40  _time = copy._time;
41 }
42 
43 /**
44  * Returns an HTTPDate that represents the current time and date.
45  */
46 INLINE HTTPDate HTTPDate::
47 now() {
48  return HTTPDate(time(nullptr));
49 }
50 
51 /**
52  * Returns true if the date is meaningful, or false if it is -1 (which
53  * generally indicates the source string could not be parsed.)
54  */
55 INLINE bool HTTPDate::
56 is_valid() const {
57  return (_time != (time_t)(-1));
58 }
59 
60 /**
61  * Returns the date as a C time_t value.
62  */
63 INLINE time_t HTTPDate::
64 get_time() const {
65  return _time;
66 }
67 
68 /**
69  *
70  */
71 INLINE bool HTTPDate::
72 operator == (const HTTPDate &other) const {
73  return _time == other._time;
74 }
75 
76 /**
77  *
78  */
79 INLINE bool HTTPDate::
80 operator != (const HTTPDate &other) const {
81  return !operator == (other);
82 }
83 
84 /**
85  *
86  */
87 INLINE bool HTTPDate::
88 operator < (const HTTPDate &other) const {
89  return _time < other._time;
90 }
91 
92 /**
93  *
94  */
95 INLINE bool HTTPDate::
96 operator > (const HTTPDate &other) const {
97  return _time > other._time;
98 }
99 
100 /**
101  * Returns a number less than zero if this HTTPDate sorts before the other
102  * one, greater than zero if it sorts after, or zero if they are equivalent.
103  */
104 INLINE int HTTPDate::
105 compare_to(const HTTPDate &other) const {
106  return (int)(_time - other._time);
107 }
108 
109 /**
110  *
111  */
112 INLINE void HTTPDate::
113 operator += (int seconds) {
114  _time += seconds;
115 }
116 
117 /**
118  *
119  */
120 INLINE void HTTPDate::
121 operator -= (int seconds) {
122  _time -= seconds;
123 }
124 
125 /**
126  *
127  */
128 INLINE HTTPDate HTTPDate::
129 operator + (int seconds) const {
130  return HTTPDate(_time + seconds);
131 }
132 
133 /**
134  *
135  */
136 INLINE HTTPDate HTTPDate::
137 operator - (int seconds) const {
138  return HTTPDate(_time - seconds);
139 }
140 
141 /**
142  *
143  */
144 INLINE int HTTPDate::
145 operator - (const HTTPDate &other) const {
146  return (int)(_time - other._time);
147 }
148 
149 
150 INLINE std::istream &
151 operator >> (std::istream &in, HTTPDate &date) {
152  if (!date.input(in)) {
153  in.clear(std::ios::failbit | in.rdstate());
154  }
155  return in;
156 }
157 
158 INLINE std::ostream &
159 operator << (std::ostream &out, const HTTPDate &date) {
160  date.output(out);
161  return out;
162 }
bool is_valid() const
Returns true if the date is meaningful, or false if it is -1 (which generally indicates the source st...
Definition: httpDate.I:56
int compare_to(const HTTPDate &other) const
Returns a number less than zero if this HTTPDate sorts before the other one, greater than zero if it ...
Definition: httpDate.I:105
A container for an HTTP-legal time/date indication.
Definition: httpDate.h:27
static HTTPDate now()
Returns an HTTPDate that represents the current time and date.
Definition: httpDate.I:47
time_t get_time() const
Returns the date as a C time_t value.
Definition: httpDate.I:64