~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/time.cc

  • Committer: Monty Taylor
  • Date: 2008-10-20 08:48:34 UTC
  • mfrom: (520.1.22 drizzle)
  • Revision ID: monty@inaugust.com-20081020084834-xpb3w01vkcp55o02
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year)
100
100
{
101
101
  uint32_t days;
102
 
  ulong daynr=calc_daynr(l_time->year,l_time->month,l_time->day);
103
 
  ulong first_daynr=calc_daynr(l_time->year,1,1);
 
102
  uint32_t daynr= calc_daynr(l_time->year,l_time->month,l_time->day);
 
103
  uint32_t first_daynr= calc_daynr(l_time->year,1,1);
104
104
  bool monday_first= test(week_behaviour & WEEK_MONDAY_FIRST);
105
105
  bool week_year= test(week_behaviour & WEEK_YEAR);
106
106
  bool first_weekday= test(week_behaviour & WEEK_FIRST_WEEKDAY);
182
182
 
183
183
        /* Functions to handle periods */
184
184
 
185
 
ulong convert_period_to_month(ulong period)
 
185
uint32_t convert_period_to_month(uint32_t period)
186
186
{
187
 
  ulong a,b;
 
187
  uint32_t a,b;
188
188
  if (period == 0)
189
189
    return 0L;
190
190
  if ((a=period/100) < YY_PART_YEAR)
196
196
}
197
197
 
198
198
 
199
 
ulong convert_month_to_period(ulong month)
 
199
uint32_t convert_month_to_period(uint32_t month)
200
200
{
201
 
  ulong year;
 
201
  uint32_t year;
202
202
  if (month == 0L)
203
203
    return 0L;
204
204
  if ((year=month/12) < 100)
222
222
                          uint32_t flags)
223
223
{
224
224
  int was_cut;
225
 
  THD *thd= current_thd;
 
225
  Session *session= current_session;
226
226
  enum enum_drizzle_timestamp_type ts_type;
227
227
  
228
228
  ts_type= str_to_datetime(str, length, l_time,
229
 
                           (flags | (thd->variables.sql_mode &
 
229
                           (flags | (session->variables.sql_mode &
230
230
                                     (MODE_INVALID_DATES |
231
231
                                      MODE_NO_ZERO_DATE))),
232
232
                           &was_cut);
233
233
  if (was_cut || ts_type <= DRIZZLE_TIMESTAMP_ERROR)
234
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
234
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
235
235
                                 str, length, ts_type,  NULL);
236
236
  return ts_type;
237
237
}
243
243
 
244
244
  SYNOPSIS
245
245
    TIME_to_timestamp()
246
 
      thd             - current thread
 
246
      session             - current thread
247
247
      t               - datetime in broken-down representation, 
248
248
      in_dst_time_gap - pointer to bool which is set to true if t represents
249
249
                        value which doesn't exists (falls into the spring 
254
254
     0 - t contains datetime value which is out of TIMESTAMP range.
255
255
     
256
256
*/
257
 
my_time_t TIME_to_timestamp(THD *thd, const DRIZZLE_TIME *t, bool *in_dst_time_gap)
 
257
my_time_t TIME_to_timestamp(Session *session, const DRIZZLE_TIME *t, bool *in_dst_time_gap)
258
258
{
259
259
  my_time_t timestamp;
260
260
 
261
261
  *in_dst_time_gap= 0;
262
 
  thd->time_zone_used= 1;
 
262
  session->time_zone_used= 1;
263
263
 
264
 
  timestamp= thd->variables.time_zone->TIME_to_gmt_sec(t, in_dst_time_gap);
 
264
  timestamp= session->variables.time_zone->TIME_to_gmt_sec(t, in_dst_time_gap);
265
265
  if (timestamp)
266
266
  {
267
267
    return timestamp;
285
285
  int warning;
286
286
  bool ret_val= str_to_time(str, length, l_time, &warning);
287
287
  if (ret_val || warning)
288
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
288
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
289
289
                                 str, length, DRIZZLE_TIMESTAMP_TIME, NULL);
290
290
  return ret_val;
291
291
}
445
445
      separators++;
446
446
      /* Store in separator_map which parts are punct characters */
447
447
      if (my_ispunct(&my_charset_utf8_general_ci, *ptr))
448
 
        separator_map|= (ulong) 1 << (offset-1);
 
448
        separator_map|= 1 << (offset-1);
449
449
      else if (!my_isspace(&my_charset_utf8_general_ci, *ptr))
450
450
        return 1;
451
451
    }
482
482
    /* remove fractional seconds from later tests */
483
483
    uint32_t pos= dt_pos[6] -1;
484
484
    /* Remove separator before %f from sep map */
485
 
    separator_map= ((separator_map & ((ulong) (1 << pos)-1)) |
486
 
                    ((separator_map & ~((ulong) (1 << pos)-1)) >> 1));
 
485
    separator_map= ((separator_map & ((1 << pos)-1)) |
 
486
                    ((separator_map & ~((1 << pos)-1)) >> 1));
487
487
    if (part_map & 64)                        
488
488
    {
489
489
      separators--;                             // There is always a separator
508
508
  */
509
509
  offset= dt_pos[6] <= 3 ? 3 : 6;
510
510
  /* Remove separator before %p from sep map */
511
 
  separator_map= ((separator_map & ((ulong) (1 << offset)-1)) |
512
 
                  ((separator_map & ~((ulong) (1 << offset)-1)) >> 1));
 
511
  separator_map= ((separator_map & ((1 << offset)-1)) |
 
512
                  ((separator_map & ~((1 << offset)-1)) >> 1));
513
513
 
514
514
  format_str= 0;
515
515
  switch (format_type) {
592
592
  {
593
593
    tmp.format.str=    (char*) format_str;
594
594
    tmp.format.length= format_length;
595
 
    return date_time_format_copy((THD *)0, &tmp);
 
595
    return date_time_format_copy((Session *)0, &tmp);
596
596
  }
597
597
  return 0;
598
598
}
603
603
 
604
604
  SYNOPSIS
605
605
    date_and_time_format_copy()
606
 
    thd                 Set if variable should be allocated in thread mem
 
606
    session                     Set if variable should be allocated in thread mem
607
607
    format              format to copy
608
608
 
609
609
  NOTES
614
614
    new object
615
615
*/
616
616
 
617
 
DATE_TIME_FORMAT *date_time_format_copy(THD *thd, DATE_TIME_FORMAT *format)
 
617
DATE_TIME_FORMAT *date_time_format_copy(Session *session, DATE_TIME_FORMAT *format)
618
618
{
619
619
  DATE_TIME_FORMAT *new_format;
620
 
  ulong length= sizeof(*format) + format->format.length + 1;
 
620
  uint32_t length= sizeof(*format) + format->format.length + 1;
621
621
 
622
 
  if (thd)
623
 
    new_format= (DATE_TIME_FORMAT *) thd->alloc(length);
 
622
  if (session)
 
623
    new_format= (DATE_TIME_FORMAT *) session->alloc(length);
624
624
  else
625
625
    new_format=  (DATE_TIME_FORMAT *) my_malloc(length, MYF(MY_WME));
626
626
  if (new_format)
714
714
}
715
715
 
716
716
 
717
 
void make_truncated_value_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
 
717
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
718
718
                                  const char *str_val,
719
719
                                  uint32_t str_length,
720
720
                                  enum enum_drizzle_timestamp_type time_type,
744
744
    cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
745
745
                       ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
746
746
                       type_str, str.c_ptr(), field_name,
747
 
                       (ulong) thd->row_count);
 
747
                       (uint32_t) session->row_count);
748
748
  else
749
749
  {
750
750
    if (time_type > DRIZZLE_TIMESTAMP_ERROR)
755
755
      cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
756
756
                         ER(ER_WRONG_VALUE), type_str, str.c_ptr());
757
757
  }
758
 
  push_warning(thd, level,
 
758
  push_warning(session, level,
759
759
               ER_TRUNCATED_WRONG_VALUE, warn_buff);
760
760
}
761
761
 
826
826
    period= (calc_daynr(ltime->year,ltime->month,ltime->day) +
827
827
             sign * (long) interval.day);
828
828
    /* Daynumber from year 0 to 9999-12-31 */
829
 
    if ((ulong) period > MAX_DAY_NUMBER)
 
829
    if (period > MAX_DAY_NUMBER)
830
830
      goto invalid_date;
831
831
    get_date_from_daynr((long) period,&ltime->year,&ltime->month,&ltime->day);
832
832
    break;
833
833
  case INTERVAL_YEAR:
834
834
    ltime->year+= sign * (long) interval.year;
835
 
    if ((ulong) ltime->year >= 10000L)
 
835
    if (ltime->year >= 10000L)
836
836
      goto invalid_date;
837
837
    if (ltime->month == 2 && ltime->day == 29 &&
838
838
        calc_days_in_year(ltime->year) != 366)
843
843
  case INTERVAL_MONTH:
844
844
    period= (ltime->year*12 + sign * (long) interval.year*12 +
845
845
             ltime->month-1 + sign * (long) interval.month);
846
 
    if ((ulong) period >= 120000L)
 
846
    if (period >= 120000L)
847
847
      goto invalid_date;
848
848
    ltime->year= (uint) (period / 12);
849
849
    ltime->month= (uint) (period % 12L)+1;
862
862
  return 0;                                     // Ok
863
863
 
864
864
invalid_date:
865
 
  push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
865
  push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
866
866
                      ER_DATETIME_FUNCTION_OVERFLOW,
867
867
                      ER(ER_DATETIME_FUNCTION_OVERFLOW),
868
868
                      "datetime");