~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal_format.cc

  • Committer: Brian Aker
  • Date: 2009-02-04 18:28:00 UTC
  • mfrom: (813.1.26 new-temporal)
  • Revision ID: brian@tangent.org-20090204182800-ra3p8rlu4zrs9fvn
Merge from Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
, _minute_part_index(0)
53
53
, _second_part_index(0)
54
54
, _usecond_part_index(0)
 
55
, _nsecond_part_index(0)
55
56
{
56
57
  /* Make sure we've got no junk in the match_vector. */
57
58
  memset(_match_vector, 0, sizeof(_match_vector));
157
158
  {
158
159
    size_t usecond_start= _match_vector[_usecond_part_index];
159
160
    size_t usecond_len= _match_vector[_usecond_part_index + 1] - _match_vector[_usecond_part_index];
160
 
    to->_useconds= atoi(copy_data.substr(usecond_start, usecond_len).c_str());
 
161
    /* 
 
162
     * For microseconds, which are millionth of 1 second, 
 
163
     * we must ensure that we produce a correct result, 
 
164
     * even if < 6 places were specified.  For instance, if we get .1, 
 
165
     * we must produce 100000. .11 should produce 110000, etc.
 
166
     */
 
167
    uint32_t multiplier= 1;
 
168
    int32_t x= usecond_len;
 
169
    while (x < 6)
 
170
    {
 
171
      multiplier*= 10;
 
172
      ++x;
 
173
    }
 
174
    to->_useconds= atoi(copy_data.substr(usecond_start, usecond_len).c_str()) * multiplier;
161
175
  }
162
176
  if (_nsecond_part_index > 1)
163
177
  {
164
178
    size_t nsecond_start= _match_vector[_nsecond_part_index];
165
179
    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());
 
180
    /* 
 
181
     * For nanoseconds, which are 1 billionth of a second, 
 
182
     * we must ensure that we produce a correct result, 
 
183
     * even if < 9 places were specified.  For instance, if we get .1, 
 
184
     * we must produce 100000000. .11 should produce 110000000, etc.
 
185
     */
 
186
    uint32_t multiplier= 1;
 
187
    int32_t x= nsecond_len;
 
188
    while (x < 9)
 
189
    {
 
190
      multiplier*= 10;
 
191
      ++x;
 
192
    }
 
193
    to->_nseconds= atoi(copy_data.substr(nsecond_start, nsecond_len).c_str()) * multiplier;
167
194
  }
168
195
  return true;
169
196
}
170
197
 
171
198
} /* end namespace drizzled */
172
199
 
173
 
#define COUNT_KNOWN_FORMATS 13
 
200
#define COUNT_KNOWN_FORMATS 14
174
201
 
175
202
struct temporal_format_args
176
203
{
199
226
 */
200
227
static struct temporal_format_args __format_args[COUNT_KNOWN_FORMATS]= 
201
228
{
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 */
 
229
  {"^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})\\.(\\d{1,6})$", 1, 2, 3, 4, 5, 6, 7, 0} /* YYYYMMDDHHmmSS.uuuuuu */
203
230
, {"^(\\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 */
 
231
, {"^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{1,6})$", 1, 2, 3, 4, 5, 6, 7, 0} /* YYYY[/-.]MM[/-.]DD[T]HH:mm:SS.uuuuuu */
205
232
, {"^(\\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
233
, {"^(\\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
234
, {"^(\\d{4})(\\d{2})(\\d{2})$", 1, 2, 3, 0, 0, 0, 0, 0} /* YYYYMMDD */
208
235
, {"^(\\d{2})[-/.]*(\\d{2})[-/.]*(\\d{4})$", 3, 1, 2, 0, 0, 0, 0, 0} /* MM[-/.]DD[-/.]YYYY (US common format)*/
209
236
, {"^(\\d{2})[-/.]*(\\d{2})[-/.]*(\\d{2})$", 1, 2, 3, 0, 0, 0, 0, 0} /* YY[-/.]MM[-/.]DD */
210
237
, {"^(\\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 */
 
238
, {"^(\\d{2}):*(\\d{2}):*(\\d{2})\\.(\\d{1,6})$", 0, 0, 0, 1, 2, 3, 4, 0} /* HHmmSS.uuuuuu, HH:mm:SS.uuuuuu */
212
239
, {"^(\\d{1,2}):*(\\d{2}):*(\\d{2})$", 0, 0, 0, 1, 2, 3, 0, 0} /* [H]HmmSS, [H]H:mm:SS */
213
240
, {"^(\\d{1,2}):*(\\d{2})$", 0, 0, 0, 0, 1, 2, 0, 0} /* [m]mSS, [m]m:SS */
214
241
, {"^(\\d{1,2})$", 0, 0, 0, 0, 0, 1, 0, 0} /* SS, S */
 
242
, {"^(\\d{1,2})\\.(\\d{1,6})$", 0, 0, 0, 0, 0, 1, 2, 0} /* [S]S.uuuuuu */
215
243
};
216
244
 
217
245
std::vector<drizzled::TemporalFormat*> known_datetime_formats;