36 static char rcsid[]
not_used =
"$Id$";
42 #include <AttrTable.h>
44 #include <dods-datatypes.h>
45 #include <dods-limits.h>
57 AttrTable *at = dds.get_attr_table().find_container(attribute_name);
59 throw Error(unknown_error,
60 string(
"DODS_Date_Factory requires that the ")
62 +
string(
"DODS_Date attribute be present."));
64 string year_name = at->get_attr(
"year_variable");
65 string year_base = at->get_attr(
"year_base");
66 string month_name = at->get_attr(
"month_variable");
67 string day_name = at->get_attr(
"day_variable");
68 string year_day_name = at->get_attr(
"year_day_variable");
69 string month_day_name = at->get_attr(
"month_day_const");
73 if (year_day_name ==
"" && day_name !=
"")
75 else if (year_day_name !=
"" && day_name ==
"")
77 else if (year_day_name ==
"" && day_name ==
"")
80 throw Error(unknown_error,
81 "DODS_Date_Factory requires that one, and only one, of the attributes\n\
82 day_variable or year_day_variable be present.");
89 const char *c = year_base.c_str();
91 _year_base = strtol(c, &c2, 0);
92 if (c == c2 || _year_base == DODS_LONG_MAX || _year_base == DODS_LONG_MIN)
93 throw Error(unknown_error,
94 "The year_base attribute value cannot be converted to a valid integer.");
100 if (_format ==
ym && month_day_name !=
"")
102 const char *c = month_day_name.c_str();
104 _month_day = strtol(c, &c2, 0);
105 if (c == c2 || _month_day == DODS_LONG_MAX || _month_day == DODS_LONG_MIN)
106 throw Error(unknown_error,
107 "The month_day attribute value cannot be converted to a valid integer.");
113 _year = dds.var(year_name);
114 if ((_year->type() != dods_int16_c) && (_year->type() != dods_uint16_c) &&
115 (_year->type() != dods_int32_c) && (_year->type() != dods_uint32_c))
116 throw Error(unknown_error,
"DODS_Date_Factory: The variable used for the year must be an integer.");
120 _month = dds.var(month_name);
122 throw Error(unknown_error,
123 "DODS_Date_Factory: The variable used for the month must be an integer.");
125 _day = dds.var(day_name);
127 throw Error(unknown_error,
128 "DODS_Date_Factory: The variable used for days must be an integer.");
136 _year_day = dds.var(year_day_name);
138 throw Error(unknown_error,
139 "DODS_Date_Factory: The variable used for the year-day must be an integer.");
143 _month = dds.var(month_name);
145 throw Error(unknown_error,
146 "DODS_Date_Factory: The variable used for the month must be an integer.");
153 throw Error(unknown_error,
154 "DODS_Date_Factory: Not able to figure out the date format.");
169 return DODS_Date(year + _year_base, month, day);
176 return DODS_Date(year + _year_base, year_day);
183 int day = _month_day;
186 return DODS_Date(year + _year_base, month, day, fmt);
191 throw Error(unknown_error,
192 "DODS_Date_Factory: Unknown date format, should never get here!");
bool is_integer_type(BaseType *btp)
dods_uint32 get_integer_value(BaseType *var)
Get the value of the BaseType Variable.
date_format
Constants used to denote different supported date formats.
virtual DODS_Date get()
Read a date value from a dataset.