bes  Updated for version 3.20.6
DODS_Date.h
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of ff_handler a FreeForm API handler for the OPeNDAP
5 // DAP2 data server.
6 
7 // Copyright (c) 2005 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This is free software; you can redistribute it and/or modify it under the
11 // terms of the GNU Lesser General Public License as published by the Free
12 // Software Foundation; either version 2.1 of the License, or (at your
13 // option) any later version.
14 //
15 // This software is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 // License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 
27 // (c) COPYRIGHT URI/MIT 1998
28 // Please read the full copyright statement in the file COPYRIGHT.
29 //
30 // Authors:
31 // jhrg,jimg James Gallagher (jgallagher@gso.uri.edu)
32 
33 // $Log: DODS_Date.h,v $
34 // Revision 1.8 2001/09/28 23:19:43 jimg
35 // Merged with 3.2.3.
36 //
37 // Revision 1.7.2.1 2001/05/23 18:25:49 dan
38 // Modified to support year/month date representations,
39 // and to support ISO8601 output formats.
40 //
41 // Revision 1.6 1999/07/22 21:28:08 jimg
42 // Merged changes from the release-3-0-2 branch
43 //
44 // Revision 1.5.6.1 1999/06/01 15:38:06 jimg
45 // Added code to parse and return floating point dates.
46 //
47 // Revision 1.5 1999/05/04 02:55:35 jimg
48 // Merge with no-gnu
49 //
50 // Revision 1.4.6.1 1999/05/01 04:40:30 brent
51 // converted old String.h to the new std C++ <string> code
52 //
53 // Revision 1.4 1999/01/08 22:08:18 jimg
54 // Fixed doc++ comments.
55 //
56 // Revision 1.3 1999/01/05 00:34:45 jimg
57 // Removed string class; replaced with the GNU String class. It seems those
58 // don't mix well.
59 // Switched to simpler method names.
60 // Added the date_format enumerated type.
61 //
62 // Revision 1.2 1998/12/30 02:01:12 jimg
63 // Added class invariant.
64 //
65 // Revision 1.1 1998/12/28 19:08:26 jimg
66 // Initial version of the DODS_Date object
67 //
68 
69 #ifndef _dods_date_h
70 #define _dods_date_h
71 
72 
73 #include <time.h>
74 
75 #include <string>
76 
77 #include "BaseType.h"
78 #include "date_proc.h"
79 
80 using namespace libdap ;
81 
84 const double seconds_per_day = 86400.0;
85 const double seconds_per_hour = 3600.0;
86 const double seconds_per_minute = 60.0;
87 
91 enum date_format {
92  unknown_format,
93  ymd,
94  yd,
95  ym,
96  decimal,
97  iso8601
98 };
99 
108 class DODS_Date {
109 private:
110  long _julian_day;
111  int _year;
112  int _month;
113  int _day;
114  int _day_number;
115  date_format _format;
116 
117  void parse_fractional_time(string date);
118  void parse_integer_time(string date);
119  void parse_iso8601_time(string date);
120 
121 public:
129  DODS_Date();
130 
138  DODS_Date(string date_str);
139 
146  DODS_Date(BaseType *arg);
147 
154  DODS_Date(int year, int day_num);
155 
162  DODS_Date(int year, int month, int day);
163  DODS_Date(int year, int month, int day, date_format format);
165 
170  void set(string date);
171 
174  void set(BaseType *arg);
175 
178  void set(int year, int day_number);
179 
182  void set(int year, int month, int day);
183 
187  void set(int year, int month, int day, date_format format);
188 
190 
202  string get(date_format format = ymd) const;
203 
205  int year() const;
206 
208  int month() const;
209 
211  int day() const;
212 
214  int day_number() const;
215 
217  long julian_day() const;
218 
220  date_format format() const;
221 
231  time_t unix_time() const;
232 
233  /* Get the date as a real number. The year is the whole number and days
234  are as fractions of a year. E.G.: 1998.5 is approximately June, 1998.
235 
236  @return The date (year, month and day) as a real number. */
237  double fraction() const;
239 
242  friend int operator==(DODS_Date &d1, DODS_Date &d2);
244 
246  friend int operator!=(DODS_Date &d1, DODS_Date &d2);
247 
249  friend int operator<(DODS_Date &d1, DODS_Date &d2);
250 
252  friend int operator>(DODS_Date &d1, DODS_Date &d2);
253 
255  friend int operator<=(DODS_Date &d1, DODS_Date &d2);
256 
258  friend int operator>=(DODS_Date &d1, DODS_Date &d2);
260 
264  bool OK() const;
265 };
266 
267 #endif // _dods_date_h
DODS_Date
Definition: DODS_Date.h:108
libdap
Definition: BESDapFunctionResponseCache.h:35