~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/time.cc

  • Committer: Brian Aker
  • Date: 2008-12-06 23:57:32 UTC
  • mfrom: (656.1.10 devel)
  • Revision ID: brian@tangent.org-20081206235732-jx228bczpvmxu8ww
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
  'interval_type_to_name' is ordered and sorted on interval size and
38
38
  interval complexity.
39
 
  Order of elements in 'interval_type_to_name' should correspond to 
 
39
  Order of elements in 'interval_type_to_name' should correspond to
40
40
  the order of elements in 'interval_type' enum
41
 
  
 
41
 
42
42
  See also interval_type, interval_names
43
43
*/
44
44
 
63
63
  { C_STRING_WITH_LEN("HOUR_MICROSECOND")},
64
64
  { C_STRING_WITH_LEN("MINUTE_MICROSECOND")},
65
65
  { C_STRING_WITH_LEN("SECOND_MICROSECOND")}
66
 
}; 
 
66
};
67
67
 
68
68
        /* Calc weekday from daynr */
69
69
        /* Returns 0 for monday, 1 for tuesday .... */
95
95
                                        to ISO 8601:1988
96
96
                          If set        The week that contains the first
97
97
                                        'first-day-of-week' is week 1.
98
 
        
 
98
 
99
99
        ISO 8601:1988 means that if the week containing January 1 has
100
100
        four or more days in the new year, then it is week 1;
101
101
        Otherwise it is the last week of the previous year, and the
216
216
 
217
217
 
218
218
/*
219
 
  Convert a timestamp string to a DRIZZLE_TIME value and produce a warning 
 
219
  Convert a timestamp string to a DRIZZLE_TIME value and produce a warning
220
220
  if string was truncated during conversion.
221
221
 
222
222
  NOTE
230
230
  int was_cut;
231
231
  Session *session= current_session;
232
232
  enum enum_drizzle_timestamp_type ts_type;
233
 
  
 
233
 
234
234
  ts_type= str_to_datetime(str, length, l_time,
235
235
                           (flags | (session->variables.sql_mode &
236
236
                                     (MODE_INVALID_DATES |
244
244
 
245
245
 
246
246
/*
247
 
  Convert a datetime from broken-down DRIZZLE_TIME representation to corresponding 
 
247
  Convert a datetime from broken-down DRIZZLE_TIME representation to corresponding
248
248
  TIMESTAMP value.
249
249
 
250
250
  SYNOPSIS
251
251
    TIME_to_timestamp()
252
252
      session             - current thread
253
 
      t               - datetime in broken-down representation, 
 
253
      t               - datetime in broken-down representation,
254
254
      in_dst_time_gap - pointer to bool which is set to true if t represents
255
 
                        value which doesn't exists (falls into the spring 
 
255
                        value which doesn't exists (falls into the spring
256
256
                        time-gap) or to false otherwise.
257
 
   
 
257
 
258
258
  RETURN
259
259
     Number seconds in UTC since start of Unix Epoch corresponding to t.
260
260
     0 - t contains datetime value which is out of TIMESTAMP range.
261
 
     
 
261
 
262
262
*/
263
263
my_time_t TIME_to_timestamp(Session *session, const DRIZZLE_TIME *t,
264
264
                            bool *in_dst_time_gap)
355
355
    1   error
356
356
*/
357
357
 
358
 
bool parse_date_time_format(enum enum_drizzle_timestamp_type format_type, 
 
358
bool parse_date_time_format(enum enum_drizzle_timestamp_type format_type,
359
359
                            const char *format, uint32_t format_length,
360
360
                            DATE_TIME_FORMAT *date_time_format)
361
361
{
490
490
    /* Remove separator before %f from sep map */
491
491
    separator_map= ((separator_map & ((1 << pos)-1)) |
492
492
                    ((separator_map & ~((1 << pos)-1)) >> 1));
493
 
    if (part_map & 64)                        
 
493
    if (part_map & 64)
494
494
    {
495
495
      separators--;                             // There is always a separator
496
496
      need_p= 1;                                // force use of separators
505
505
  {
506
506
    if (need_p && parts[7] != parts[6]+2)
507
507
      separators--;
508
 
  }     
 
508
  }
509
509
  /*
510
510
    Calculate if %p is in first or last part of the datetime field
511
511
 
532
532
    */
533
533
    if (format_length == 6 && !need_p &&
534
534
        !my_strnncoll(&my_charset_bin,
535
 
                      (const unsigned char *) format, 6, 
 
535
                      (const unsigned char *) format, 6,
536
536
                      (const unsigned char *) format_str, 6))
537
537
      return 0;
538
538
    if (separator_map == (1 | 2))
554
554
      Between DATE and TIME we also allow space as separator
555
555
    */
556
556
    if ((format_length == 12 && !need_p &&
557
 
         !my_strnncoll(&my_charset_bin, 
 
557
         !my_strnncoll(&my_charset_bin,
558
558
                       (const unsigned char *) format, 12,
559
559
                       (const unsigned char*) known_date_time_formats[INTERNAL_FORMAT].datetime_format,
560
560
                       12)) ||
680
680
 
681
681
/****************************************************************************
682
682
  Functions to create default time/date/datetime strings
683
 
 
 
683
 
684
684
  NOTE:
685
685
    For the moment the DATE_TIME_FORMAT argument is ignored becasue
686
686
    MySQL doesn't support comparing of date/time/datetime strings that
687
687
    are not in arbutary order as dates are compared as strings in some
688
688
    context)
689
689
    This functions don't check that given DRIZZLE_TIME structure members are
690
 
    in valid range. If they are not, return value won't reflect any 
 
690
    in valid range. If they are not, return value won't reflect any
691
691
    valid date either. Additionally, make_time doesn't take into
692
692
    account time->day member: it's assumed that days have been converted
693
693
    to hours already.
735
735
  str[str_length]= 0;               // Ensure we have end 0 for snprintf
736
736
 
737
737
  switch (time_type) {
738
 
    case DRIZZLE_TIMESTAMP_DATE: 
 
738
    case DRIZZLE_TIMESTAMP_DATE:
739
739
      type_str= "date";
740
740
      break;
741
741
    case DRIZZLE_TIMESTAMP_TIME: