~fallenpegasus/drizzle/returning

« back to all changes in this revision

Viewing changes to drizzled/temporal_format.cc

  • Committer: Mark Atwood
  • Date: 2009-01-30 19:10:37 UTC
  • mfrom: (819.1.1 drizzle)
  • Revision ID: me@mark.atwood.name-20090130191037-fma4950t6ewayxud
mergeĀ fromĀ main

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
                              + (_hour_part_index > 1 ? 1 : 0)
99
99
                              + (_minute_part_index > 1 ? 1 : 0)
100
100
                              + (_second_part_index > 1 ? 1 : 0)
 
101
                              + (_usecond_part_index > 1 ? 1 : 0)
 
102
                              + (_nsecond_part_index > 1 ? 1 : 0)
101
103
                              + 1; /* Add one for the entire match... */
102
104
  if (result != expected_match_count)
103
105
    return false;
157
159
    size_t usecond_len= _match_vector[_usecond_part_index + 1] - _match_vector[_usecond_part_index];
158
160
    to->_useconds= atoi(copy_data.substr(usecond_start, usecond_len).c_str());
159
161
  }
 
162
  if (_nsecond_part_index > 1)
 
163
  {
 
164
    size_t nsecond_start= _match_vector[_nsecond_part_index];
 
165
    size_t nsecond_len= _match_vector[_nsecond_part_index + 1] - _match_vector[_nsecond_part_index];
 
166
    to->_nseconds= atoi(copy_data.substr(nsecond_start, nsecond_len).c_str());
 
167
  }
160
168
  return true;
161
169
}
162
170
 
163
171
} /* end namespace drizzled */
164
172
 
165
 
#define COUNT_KNOWN_FORMATS 12
 
173
#define COUNT_KNOWN_FORMATS 13
166
174
 
167
175
struct temporal_format_args
168
176
{
174
182
  int32_t minute_part_index;
175
183
  int32_t second_part_index;
176
184
  int32_t usecond_part_index;
 
185
  int32_t nsecond_part_index;
177
186
};
178
187
 
179
188
/**
190
199
 */
191
200
static struct temporal_format_args __format_args[COUNT_KNOWN_FORMATS]= 
192
201
{
193
 
  {"(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})", 1, 2, 3, 4, 5, 6, 0} /* YYYYMMDDHHmmSS */
194
 
, {"(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})\\.(\\d{6})", 1, 2, 3, 4, 5, 6, 7} /* YYYYMMDDHHmmSS.uuuuuu */
195
 
, {"(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})", 1, 2, 3, 4, 5, 6, 0} /* YYYY-MM-DD[T]HH:mm:SS, YYYY.MM.DD[T]HH:mm:SS, YYYY/MM/DD[T]HH:mm:SS*/
196
 
, {"(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})", 1, 2, 3, 0, 0, 0, 0} /* YYYY-MM-DD, YYYY.MM.DD, YYYY/MM/DD */
197
 
, {"(\\d{4})(\\d{2})(\\d{2})", 1, 2, 3, 0, 0, 0, 0} /* YYYYMMDD */
198
 
, {"(\\d{2})[-/.]*(\\d{2})[-/.]*(\\d{4})", 3, 1, 2, 0, 0, 0, 0} /* MM[-/.]DD[-/.]YYYY (US common format)*/
199
 
, {"(\\d{2})[-/.]*(\\d{2})[-/.]*(\\d{2})", 1, 2, 3, 0, 0, 0, 0} /* YY[-/.]MM[-/.]DD */
200
 
, {"(\\d{2})[-/.]*(\\d{1,2})[-/.]*(\\d{1,2})", 1, 2, 3, 0, 0, 0, 0} /* YY[-/.][M]M[-/.][D]D */
201
 
, {"(\\d{2}):*(\\d{2}):*(\\d{2})\\.(\\d{6})", 0, 0, 0, 1, 2, 3, 4} /* HHmmSS.uuuuuu, HH:mm:SS.uuuuuu */
202
 
, {"(\\d{1,2}):*(\\d{2}):*(\\d{2})", 0, 0, 0, 1, 2, 3, 0} /* [H]HmmSS, [H]H:mm:SS */
203
 
, {"(\\d{1,2}):*(\\d{2})", 0, 0, 0, 0, 1, 2, 0} /* [m]mSS, [m]m:SS */
204
 
, {"(\\d{1,2})", 0, 0, 0, 0, 0, 1, 0} /* SS, S */
 
202
  {"^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})\\.(\\d{6})$", 1, 2, 3, 4, 5, 6, 7, 0} /* YYYYMMDDHHmmSS.uuuuuu */
 
203
, {"^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})$", 1, 2, 3, 4, 5, 6, 0, 0} /* YYYYMMDDHHmmSS */
 
204
, {"^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{6})$", 1, 2, 3, 4, 5, 6, 7, 0} /* YYYY[/-.]MM[/-.]DD[T]HH:mm:SS.uuuuuu */
 
205
, {"^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})$", 1, 2, 3, 4, 5, 6, 0, 0} /* YYYY[/-.]MM[/-.]DD[T]HH:mm:SS */
 
206
, {"^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})$", 1, 2, 3, 0, 0, 0, 0, 0} /* YYYY-MM-DD, YYYY.MM.DD, YYYY/MM/DD */
 
207
, {"^(\\d{4})(\\d{2})(\\d{2})$", 1, 2, 3, 0, 0, 0, 0, 0} /* YYYYMMDD */
 
208
, {"^(\\d{2})[-/.]*(\\d{2})[-/.]*(\\d{4})$", 3, 1, 2, 0, 0, 0, 0, 0} /* MM[-/.]DD[-/.]YYYY (US common format)*/
 
209
, {"^(\\d{2})[-/.]*(\\d{2})[-/.]*(\\d{2})$", 1, 2, 3, 0, 0, 0, 0, 0} /* YY[-/.]MM[-/.]DD */
 
210
, {"^(\\d{2})[-/.]*(\\d{1,2})[-/.]*(\\d{1,2})$", 1, 2, 3, 0, 0, 0, 0, 0} /* YY[-/.][M]M[-/.][D]D */
 
211
, {"^(\\d{2}):*(\\d{2}):*(\\d{2})\\.(\\d{6})$", 0, 0, 0, 1, 2, 3, 4, 0} /* HHmmSS.uuuuuu, HH:mm:SS.uuuuuu */
 
212
, {"^(\\d{1,2}):*(\\d{2}):*(\\d{2})$", 0, 0, 0, 1, 2, 3, 0, 0} /* [H]HmmSS, [H]H:mm:SS */
 
213
, {"^(\\d{1,2}):*(\\d{2})$", 0, 0, 0, 0, 1, 2, 0, 0} /* [m]mSS, [m]m:SS */
 
214
, {"^(\\d{1,2})$", 0, 0, 0, 0, 0, 1, 0, 0} /* SS, S */
205
215
};
206
216
 
207
217
std::vector<drizzled::TemporalFormat*> known_datetime_formats;
231
241
    tmp->set_minute_part_index(current_format_args.minute_part_index);
232
242
    tmp->set_second_part_index(current_format_args.second_part_index);
233
243
    tmp->set_usecond_part_index(current_format_args.usecond_part_index);
 
244
    tmp->set_nsecond_part_index(current_format_args.nsecond_part_index);
234
245
 
235
 
    if (current_format_args.year_part_index > 0)
 
246
    if (current_format_args.year_part_index > 0) /* A date must have a year */
236
247
    {
237
248
      known_datetime_formats.push_back(tmp);
238
 
      if (current_format_args.hour_part_index == 0)
 
249
      if (current_format_args.second_part_index == 0) /* A time must have seconds. */
239
250
        known_date_formats.push_back(tmp);
240
251
    }
241
 
    if (current_format_args.hour_part_index > 0)
242
 
      if (current_format_args.year_part_index == 0)
 
252
    if (current_format_args.second_part_index > 0) /* A time must have seconds, but may not have minutes or hours */
 
253
      if (current_format_args.year_part_index == 0) /* A time may not have a date part, and date parts must have a year */
243
254
        known_time_formats.push_back(tmp);
244
255
  }
245
256
  return true;