Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE HTTPDate::
18HTTPDate() : _time(-1) {
19}
20
21/**
22 *
23 */
24INLINE HTTPDate::
25HTTPDate(time_t time) : _time(time) {
26}
27
28/**
29 *
30 */
31INLINE HTTPDate::
32HTTPDate(const HTTPDate &copy) : _time(copy._time) {
33}
34
35/**
36 *
37 */
38INLINE void HTTPDate::
39operator = (const HTTPDate &copy) {
40 _time = copy._time;
41}
42
43/**
44 * Returns an HTTPDate that represents the current time and date.
45 */
47now() {
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 */
55INLINE bool HTTPDate::
56is_valid() const {
57 return (_time != (time_t)(-1));
58}
59
60/**
61 * Returns the date as a C time_t value.
62 */
63INLINE time_t HTTPDate::
64get_time() const {
65 return _time;
66}
67
68/**
69 *
70 */
71INLINE bool HTTPDate::
72operator == (const HTTPDate &other) const {
73 return _time == other._time;
74}
75
76/**
77 *
78 */
79INLINE bool HTTPDate::
80operator != (const HTTPDate &other) const {
81 return !operator == (other);
82}
83
84/**
85 *
86 */
87INLINE bool HTTPDate::
88operator < (const HTTPDate &other) const {
89 return _time < other._time;
90}
91
92/**
93 *
94 */
95INLINE bool HTTPDate::
96operator > (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 */
104INLINE int HTTPDate::
105compare_to(const HTTPDate &other) const {
106 return (int)(_time - other._time);
107}
108
109/**
110 *
111 */
112INLINE void HTTPDate::
113operator += (int seconds) {
114 _time += seconds;
115}
116
117/**
118 *
119 */
120INLINE void HTTPDate::
121operator -= (int seconds) {
122 _time -= seconds;
123}
124
125/**
126 *
127 */
128INLINE HTTPDate HTTPDate::
129operator + (int seconds) const {
130 return HTTPDate(_time + seconds);
131}
132
133/**
134 *
135 */
136INLINE HTTPDate HTTPDate::
137operator - (int seconds) const {
138 return HTTPDate(_time - seconds);
139}
140
141/**
142 *
143 */
144INLINE int HTTPDate::
145operator - (const HTTPDate &other) const {
146 return (int)(_time - other._time);
147}
148
149
150INLINE std::istream &
151operator >> (std::istream &in, HTTPDate &date) {
152 if (!date.input(in)) {
153 in.clear(std::ios::failbit | in.rdstate());
154 }
155 return in;
156}
157
158INLINE std::ostream &
159operator << (std::ostream &out, const HTTPDate &date) {
160 date.output(out);
161 return out;
162}
A container for an HTTP-legal time/date indication.
Definition httpDate.h:27
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
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
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