~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/time.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
/* Functions to handle date and time */
18
18
 
19
 
#include "mysql_priv.h"
20
 
#include <m_ctype.h>
 
19
#include <drizzled/server_includes.h>
 
20
#include <drizzled/drizzled_error_messages.h>
 
21
#include <drizzled/util/test.h>
21
22
 
22
23
 
23
24
        /* Some functions to calculate dates */
95
96
        next week is week 1.
96
97
*/
97
98
 
98
 
uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year)
 
99
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year)
99
100
{
100
 
  uint days;
 
101
  uint32_t days;
101
102
  ulong daynr=calc_daynr(l_time->year,l_time->month,l_time->day);
102
103
  ulong first_daynr=calc_daynr(l_time->year,1,1);
103
104
  bool monday_first= test(week_behaviour & WEEK_MONDAY_FIRST);
104
105
  bool week_year= test(week_behaviour & WEEK_YEAR);
105
106
  bool first_weekday= test(week_behaviour & WEEK_FIRST_WEEKDAY);
106
107
 
107
 
  uint weekday=calc_weekday(first_daynr, !monday_first);
 
108
  uint32_t weekday=calc_weekday(first_daynr, !monday_first);
108
109
  *year=l_time->year;
109
110
 
110
111
  if (l_time->month == 1 && l_time->day <= 7-weekday)
138
139
        /* Change a daynr to year, month and day */
139
140
        /* Daynr 0 is returned as date 00.00.00 */
140
141
 
141
 
void get_date_from_daynr(long daynr,uint *ret_year,uint *ret_month,
142
 
                         uint *ret_day)
 
142
void get_date_from_daynr(long daynr,uint32_t *ret_year,uint32_t *ret_month,
 
143
                         uint32_t *ret_day)
143
144
{
144
 
  uint year,temp,leap_day,day_of_year,days_in_year;
145
 
  uchar *month_pos;
 
145
  uint32_t year,temp,leap_day,day_of_year,days_in_year;
 
146
  unsigned char *month_pos;
146
147
 
147
148
  if (daynr <= 365L || daynr >= 3652500)
148
149
  {                                             /* Fix if wrong daynr */
209
210
 
210
211
 
211
212
/*
212
 
  Convert a timestamp string to a MYSQL_TIME value and produce a warning 
 
213
  Convert a timestamp string to a DRIZZLE_TIME value and produce a warning 
213
214
  if string was truncated during conversion.
214
215
 
215
216
  NOTE
216
217
    See description of str_to_datetime() for more information.
217
218
*/
218
219
 
219
 
timestamp_type
220
 
str_to_datetime_with_warn(const char *str, uint length, MYSQL_TIME *l_time,
221
 
                          uint flags)
 
220
enum enum_drizzle_timestamp_type
 
221
str_to_datetime_with_warn(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
 
222
                          uint32_t flags)
222
223
{
223
224
  int was_cut;
224
225
  THD *thd= current_thd;
225
 
  timestamp_type ts_type;
 
226
  enum enum_drizzle_timestamp_type ts_type;
226
227
  
227
228
  ts_type= str_to_datetime(str, length, l_time,
228
229
                           (flags | (thd->variables.sql_mode &
229
230
                                     (MODE_INVALID_DATES |
230
231
                                      MODE_NO_ZERO_DATE))),
231
232
                           &was_cut);
232
 
  if (was_cut || ts_type <= MYSQL_TIMESTAMP_ERROR)
233
 
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
234
 
                                 str, length, ts_type,  NullS);
 
233
  if (was_cut || ts_type <= DRIZZLE_TIMESTAMP_ERROR)
 
234
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
235
                                 str, length, ts_type,  NULL);
235
236
  return ts_type;
236
237
}
237
238
 
238
239
 
239
240
/*
240
 
  Convert a datetime from broken-down MYSQL_TIME representation to corresponding 
 
241
  Convert a datetime from broken-down DRIZZLE_TIME representation to corresponding 
241
242
  TIMESTAMP value.
242
243
 
243
244
  SYNOPSIS
253
254
     0 - t contains datetime value which is out of TIMESTAMP range.
254
255
     
255
256
*/
256
 
my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, bool *in_dst_time_gap)
 
257
my_time_t TIME_to_timestamp(THD *thd, const DRIZZLE_TIME *t, bool *in_dst_time_gap)
257
258
{
258
259
  my_time_t timestamp;
259
260
 
272
273
 
273
274
 
274
275
/*
275
 
  Convert a time string to a MYSQL_TIME struct and produce a warning
 
276
  Convert a time string to a DRIZZLE_TIME struct and produce a warning
276
277
  if string was cut during conversion.
277
278
 
278
279
  NOTE
279
280
    See str_to_time() for more info.
280
281
*/
281
282
bool
282
 
str_to_time_with_warn(const char *str, uint length, MYSQL_TIME *l_time)
 
283
str_to_time_with_warn(const char *str, uint32_t length, DRIZZLE_TIME *l_time)
283
284
{
284
285
  int warning;
285
286
  bool ret_val= str_to_time(str, length, l_time, &warning);
286
287
  if (ret_val || warning)
287
 
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
288
 
                                 str, length, MYSQL_TIMESTAMP_TIME, NullS);
 
288
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
289
                                 str, length, DRIZZLE_TIMESTAMP_TIME, NULL);
289
290
  return ret_val;
290
291
}
291
292
 
294
295
  Convert a system time structure to TIME
295
296
*/
296
297
 
297
 
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from)
 
298
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from)
298
299
{
299
300
  to->neg=0;
300
301
  to->second_part=0;
306
307
  to->second=   (int) from->tm_sec;
307
308
}
308
309
 
309
 
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds)
 
310
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds)
310
311
{
311
312
  long t_seconds;
312
313
  // to->neg is not cleared, it may already be set to a useful value
313
 
  to->time_type= MYSQL_TIMESTAMP_TIME;
 
314
  to->time_type= DRIZZLE_TIMESTAMP_TIME;
314
315
  to->year= 0;
315
316
  to->month= 0;
316
317
  to->day= 0;
348
349
    1   error
349
350
*/
350
351
 
351
 
bool parse_date_time_format(timestamp_type format_type, 
352
 
                            const char *format, uint format_length,
 
352
bool parse_date_time_format(enum enum_drizzle_timestamp_type format_type, 
 
353
                            const char *format, uint32_t format_length,
353
354
                            DATE_TIME_FORMAT *date_time_format)
354
355
{
355
 
  uint offset= 0, separators= 0;
 
356
  uint32_t offset= 0, separators= 0;
356
357
  const char *ptr= format, *format_str;
357
358
  const char *end= ptr+format_length;
358
 
  uchar *dt_pos= date_time_format->positions;
 
359
  unsigned char *dt_pos= date_time_format->positions;
359
360
  /* need_p is set if we are using AM/PM format */
360
361
  bool need_p= 0, allow_separator= 0;
361
 
  ulong part_map= 0, separator_map= 0;
 
362
  uint32_t part_map= 0, separator_map= 0;
362
363
  const char *parts[16];
363
364
 
364
365
  date_time_format->time_separator= 0;
375
376
  {
376
377
    if (*ptr == '%' && ptr+1 != end)
377
378
    {
378
 
      uint position;
 
379
      uint32_t position;
379
380
      switch (*++ptr) {
380
381
      case 'y':                                 // Year
381
382
      case 'Y':
428
429
      */
429
430
      if (part_map && position <= 2 && !(part_map & (1 | 2 | 4)))
430
431
        offset=5;
431
 
      part_map|= (ulong) 1 << position;
 
432
      part_map|= UINT32_C(1) << position;
432
433
      dt_pos[position]= offset++;
433
434
      allow_separator= 1;
434
435
    }
443
444
      allow_separator= 0;                       // Don't allow two separators
444
445
      separators++;
445
446
      /* Store in separator_map which parts are punct characters */
446
 
      if (my_ispunct(&my_charset_latin1, *ptr))
 
447
      if (my_ispunct(&my_charset_utf8_general_ci, *ptr))
447
448
        separator_map|= (ulong) 1 << (offset-1);
448
 
      else if (!my_isspace(&my_charset_latin1, *ptr))
 
449
      else if (!my_isspace(&my_charset_utf8_general_ci, *ptr))
449
450
        return 1;
450
451
    }
451
452
  }
466
467
    The last test is to ensure that %p is used if and only if
467
468
    it's needed.
468
469
  */
469
 
  if ((format_type == MYSQL_TIMESTAMP_DATETIME &&
470
 
       !test_all_bits(part_map, (1 | 2 | 4 | 8 | 16 | 32))) ||
471
 
      (format_type == MYSQL_TIMESTAMP_DATE && part_map != (1 | 2 | 4)) ||
472
 
      (format_type == MYSQL_TIMESTAMP_TIME &&
473
 
       !test_all_bits(part_map, 8 | 16 | 32)) ||
 
470
  if ((format_type == DRIZZLE_TIMESTAMP_DATETIME &&
 
471
       !test_all_bits(part_map, (uint32_t) (1 | 2 | 4 | 8 | 16 | 32))) ||
 
472
      (format_type == DRIZZLE_TIMESTAMP_DATE && part_map != (1 | 2 | 4)) ||
 
473
      (format_type == DRIZZLE_TIMESTAMP_TIME &&
 
474
       !test_all_bits(part_map, (uint32_t) (8 | 16 | 32))) ||
474
475
      !allow_separator ||                       // %option should be last
475
476
      (need_p && dt_pos[6] +1 != dt_pos[7]) ||
476
477
      (need_p ^ (dt_pos[7] != 255)))
479
480
  if (dt_pos[6] != 255)                         // If fractional seconds
480
481
  {
481
482
    /* remove fractional seconds from later tests */
482
 
    uint pos= dt_pos[6] -1;
 
483
    uint32_t pos= dt_pos[6] -1;
483
484
    /* Remove separator before %f from sep map */
484
485
    separator_map= ((separator_map & ((ulong) (1 << pos)-1)) |
485
486
                    ((separator_map & ~((ulong) (1 << pos)-1)) >> 1));
512
513
 
513
514
  format_str= 0;
514
515
  switch (format_type) {
515
 
  case MYSQL_TIMESTAMP_DATE:
 
516
  case DRIZZLE_TIMESTAMP_DATE:
516
517
    format_str= known_date_time_formats[INTERNAL_FORMAT].date_format;
517
518
    /* fall through */
518
 
  case MYSQL_TIMESTAMP_TIME:
 
519
  case DRIZZLE_TIMESTAMP_TIME:
519
520
    if (!format_str)
520
521
      format_str=known_date_time_formats[INTERNAL_FORMAT].time_format;
521
522
 
525
526
    */
526
527
    if (format_length == 6 && !need_p &&
527
528
        !my_strnncoll(&my_charset_bin,
528
 
                      (const uchar *) format, 6, 
529
 
                      (const uchar *) format_str, 6))
 
529
                      (const unsigned char *) format, 6, 
 
530
                      (const unsigned char *) format_str, 6))
530
531
      return 0;
531
532
    if (separator_map == (1 | 2))
532
533
    {
533
 
      if (format_type == MYSQL_TIMESTAMP_TIME)
 
534
      if (format_type == DRIZZLE_TIMESTAMP_TIME)
534
535
      {
535
536
        if (*(format+2) != *(format+5))
536
537
          break;                                // Error
540
541
      return 0;
541
542
    }
542
543
    break;
543
 
  case MYSQL_TIMESTAMP_DATETIME:
 
544
  case DRIZZLE_TIMESTAMP_DATETIME:
544
545
    /*
545
546
      If there is no separators, allow the internal format as we can read
546
547
      this.  If separators are used, they must be between each part.
548
549
    */
549
550
    if ((format_length == 12 && !need_p &&
550
551
         !my_strnncoll(&my_charset_bin, 
551
 
                       (const uchar *) format, 12,
552
 
                       (const uchar*) known_date_time_formats[INTERNAL_FORMAT].datetime_format,
 
552
                       (const unsigned char *) format, 12,
 
553
                       (const unsigned char*) known_date_time_formats[INTERNAL_FORMAT].datetime_format,
553
554
                       12)) ||
554
555
        (separators == 5 && separator_map == (1 | 2 | 8 | 16)))
555
556
      return 0;
572
573
    format_length       Length of string
573
574
 
574
575
  NOTES
575
 
    The returned object should be freed with my_free()
 
576
    The returned object should be freed with free()
576
577
 
577
578
  RETURN
578
579
    NULL ponter:        Error
580
581
*/
581
582
 
582
583
DATE_TIME_FORMAT
583
 
*date_time_format_make(timestamp_type format_type,
584
 
                       const char *format_str, uint format_length)
 
584
*date_time_format_make(enum enum_drizzle_timestamp_type format_type,
 
585
                       const char *format_str, uint32_t format_length)
585
586
{
586
587
  DATE_TIME_FORMAT tmp;
587
588
 
606
607
    format              format to copy
607
608
 
608
609
  NOTES
609
 
    The returned object should be freed with my_free()
 
610
    The returned object should be freed with free()
610
611
 
611
612
  RETURN
612
613
    NULL ponter:        Error
626
627
  {
627
628
    /* Put format string after current pos */
628
629
    new_format->format.str= (char*) (new_format+1);
629
 
    memcpy((char*) new_format->positions, (char*) format->positions,
 
630
    memcpy(new_format->positions, format->positions,
630
631
           sizeof(format->positions));
631
632
    new_format->time_separator= format->time_separator;
632
633
    /* We make the string null terminated for easy printf in SHOW VARIABLES */
633
 
    memcpy((char*) new_format->format.str, format->format.str,
 
634
    memcpy(new_format->format.str, format->format.str,
634
635
           format->format.length);
635
636
    new_format->format.str[format->format.length]= 0;
636
637
    new_format->format.length= format->format.length;
656
657
*/
657
658
 
658
659
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
659
 
                                     timestamp_type type)
 
660
                                     enum enum_drizzle_timestamp_type type)
660
661
{
661
662
  switch (type) {
662
 
  case MYSQL_TIMESTAMP_DATE:
 
663
  case DRIZZLE_TIMESTAMP_DATE:
663
664
    return format->date_format;
664
 
  case MYSQL_TIMESTAMP_DATETIME:
 
665
  case DRIZZLE_TIMESTAMP_DATETIME:
665
666
    return format->datetime_format;
666
 
  case MYSQL_TIMESTAMP_TIME:
 
667
  case DRIZZLE_TIMESTAMP_TIME:
667
668
    return format->time_format;
668
669
  default:
669
670
    assert(0);                          // Impossible
679
680
    MySQL doesn't support comparing of date/time/datetime strings that
680
681
    are not in arbutary order as dates are compared as strings in some
681
682
    context)
682
 
    This functions don't check that given MYSQL_TIME structure members are
 
683
    This functions don't check that given DRIZZLE_TIME structure members are
683
684
    in valid range. If they are not, return value won't reflect any 
684
685
    valid date either. Additionally, make_time doesn't take into
685
686
    account time->day member: it's assumed that days have been converted
687
688
****************************************************************************/
688
689
 
689
690
void make_time(const DATE_TIME_FORMAT *format __attribute__((unused)),
690
 
               const MYSQL_TIME *l_time, String *str)
 
691
               const DRIZZLE_TIME *l_time, String *str)
691
692
{
692
 
  uint length= (uint) my_time_to_str(l_time, (char*) str->ptr());
 
693
  uint32_t length= (uint) my_time_to_str(l_time, (char*) str->ptr());
693
694
  str->length(length);
694
695
  str->set_charset(&my_charset_bin);
695
696
}
696
697
 
697
698
 
698
699
void make_date(const DATE_TIME_FORMAT *format __attribute__((unused)),
699
 
               const MYSQL_TIME *l_time, String *str)
 
700
               const DRIZZLE_TIME *l_time, String *str)
700
701
{
701
 
  uint length= (uint) my_date_to_str(l_time, (char*) str->ptr());
 
702
  uint32_t length= (uint) my_date_to_str(l_time, (char*) str->ptr());
702
703
  str->length(length);
703
704
  str->set_charset(&my_charset_bin);
704
705
}
705
706
 
706
707
 
707
708
void make_datetime(const DATE_TIME_FORMAT *format __attribute__((unused)),
708
 
                   const MYSQL_TIME *l_time, String *str)
 
709
                   const DRIZZLE_TIME *l_time, String *str)
709
710
{
710
 
  uint length= (uint) my_datetime_to_str(l_time, (char*) str->ptr());
 
711
  uint32_t length= (uint) my_datetime_to_str(l_time, (char*) str->ptr());
711
712
  str->length(length);
712
713
  str->set_charset(&my_charset_bin);
713
714
}
714
715
 
715
716
 
716
 
void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
 
717
void make_truncated_value_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
717
718
                                  const char *str_val,
718
 
                                  uint str_length, timestamp_type time_type,
 
719
                                  uint32_t str_length,
 
720
                                  enum enum_drizzle_timestamp_type time_type,
719
721
                                  const char *field_name)
720
722
{
721
 
  char warn_buff[MYSQL_ERRMSG_SIZE];
 
723
  char warn_buff[DRIZZLE_ERRMSG_SIZE];
722
724
  const char *type_str;
723
 
  CHARSET_INFO *cs= &my_charset_latin1;
 
725
  CHARSET_INFO *cs= &my_charset_utf8_general_ci;
724
726
  char buff[128];
725
 
  String str(buff,(uint32) sizeof(buff), system_charset_info);
 
727
  String str(buff,(uint32_t) sizeof(buff), system_charset_info);
726
728
  str.copy(str_val, str_length, system_charset_info);
727
729
  str[str_length]= 0;               // Ensure we have end 0 for snprintf
728
730
 
729
731
  switch (time_type) {
730
 
    case MYSQL_TIMESTAMP_DATE: 
 
732
    case DRIZZLE_TIMESTAMP_DATE: 
731
733
      type_str= "date";
732
734
      break;
733
 
    case MYSQL_TIMESTAMP_TIME:
 
735
    case DRIZZLE_TIMESTAMP_TIME:
734
736
      type_str= "time";
735
737
      break;
736
 
    case MYSQL_TIMESTAMP_DATETIME:  // FALLTHROUGH
 
738
    case DRIZZLE_TIMESTAMP_DATETIME:  // FALLTHROUGH
737
739
    default:
738
740
      type_str= "datetime";
739
741
      break;
745
747
                       (ulong) thd->row_count);
746
748
  else
747
749
  {
748
 
    if (time_type > MYSQL_TIMESTAMP_ERROR)
 
750
    if (time_type > DRIZZLE_TIMESTAMP_ERROR)
749
751
      cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
750
752
                         ER(ER_TRUNCATED_WRONG_VALUE),
751
753
                         type_str, str.c_ptr());
760
762
/* Daynumber from year 0 to 9999-12-31 */
761
763
#define MAX_DAY_NUMBER 3652424L
762
764
 
763
 
bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval)
 
765
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval)
764
766
{
765
767
  long period, sign;
766
768
 
785
787
  case INTERVAL_DAY_HOUR:
786
788
  {
787
789
    int64_t sec, days, daynr, microseconds, extra_sec;
788
 
    ltime->time_type= MYSQL_TIMESTAMP_DATETIME; // Return full date
 
790
    ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME; // Return full date
789
791
    microseconds= ltime->second_part + sign*interval.second_part;
790
792
    extra_sec= microseconds/1000000L;
791
793
    microseconds= microseconds%1000000L;
793
795
    sec=((ltime->day-1)*3600*24L+ltime->hour*3600+ltime->minute*60+
794
796
         ltime->second +
795
797
         sign* (int64_t) (interval.day*3600*24L +
796
 
                           interval.hour*3600LL+interval.minute*60LL+
 
798
                           interval.hour*3600L+interval.minute*60L+
797
799
                           interval.second))+ extra_sec;
798
800
    if (microseconds < 0)
799
801
    {
800
 
      microseconds+= 1000000LL;
 
802
      microseconds+= 1000000L;
801
803
      sec--;
802
804
    }
803
 
    days= sec/(3600*24LL);
804
 
    sec-= days*3600*24LL;
 
805
    days= sec/(3600*24L);
 
806
    sec-= days*3600*24L;
805
807
    if (sec < 0)
806
808
    {
807
809
      days--;
808
 
      sec+= 3600*24LL;
 
810
      sec+= 3600*24L;
809
811
    }
810
812
    ltime->second_part= (uint) microseconds;
811
813
    ltime->second= (uint) (sec % 60);
860
862
  return 0;                                     // Ok
861
863
 
862
864
invalid_date:
863
 
  push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
865
  push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
864
866
                      ER_DATETIME_FUNCTION_OVERFLOW,
865
867
                      ER(ER_DATETIME_FUNCTION_OVERFLOW),
866
868
                      "datetime");
886
888
  NOTE
887
889
    This function calculates difference between l_time1 and l_time2 absolute
888
890
    values. So one should set l_sign and correct result if he want to take
889
 
    signs into account (i.e. for MYSQL_TIME values).
 
891
    signs into account (i.e. for DRIZZLE_TIME values).
890
892
 
891
893
  RETURN VALUES
892
894
    Returns sign of difference.
896
898
*/
897
899
 
898
900
bool
899
 
calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, int64_t *seconds_out,
 
901
calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign, int64_t *seconds_out,
900
902
               long *microseconds_out)
901
903
{
902
904
  long days;
904
906
  int64_t microseconds;
905
907
 
906
908
  /*
907
 
    We suppose that if first argument is MYSQL_TIMESTAMP_TIME
 
909
    We suppose that if first argument is DRIZZLE_TIMESTAMP_TIME
908
910
    the second argument should be TIMESTAMP_TIME also.
909
911
    We should check it before calc_time_diff call.
910
912
  */
911
 
  if (l_time1->time_type == MYSQL_TIMESTAMP_TIME)  // Time value
 
913
  if (l_time1->time_type == DRIZZLE_TIMESTAMP_TIME)  // Time value
912
914
    days= (long)l_time1->day - l_sign * (long)l_time2->day;
913
915
  else
914
916
  {
915
917
    days= calc_daynr((uint) l_time1->year,
916
918
                     (uint) l_time1->month,
917
919
                     (uint) l_time1->day);
918
 
    if (l_time2->time_type == MYSQL_TIMESTAMP_TIME)
 
920
    if (l_time2->time_type == DRIZZLE_TIMESTAMP_TIME)
919
921
      days-= l_sign * (long)l_time2->day;
920
922
    else
921
923
      days-= l_sign*calc_daynr((uint) l_time2->year,
923
925
                               (uint) l_time2->day);
924
926
  }
925
927
 
926
 
  microseconds= ((int64_t)days*86400LL +
 
928
  microseconds= ((int64_t)days*86400L +
927
929
                 (int64_t)(l_time1->hour*3600L +
928
930
                            l_time1->minute*60L +
929
931
                            l_time1->second) -
930
932
                 l_sign*(int64_t)(l_time2->hour*3600L +
931
933
                                   l_time2->minute*60L +
932
 
                                   l_time2->second)) * 1000000LL +
 
934
                                   l_time2->second)) * 1000000L +
933
935
                (int64_t)l_time1->second_part -
934
936
                l_sign*(int64_t)l_time2->second_part;
935
937
 
946
948
 
947
949
 
948
950
/*
949
 
  Compares 2 MYSQL_TIME structures
 
951
  Compares 2 DRIZZLE_TIME structures
950
952
 
951
953
  SYNOPSIS
952
954
    my_time_compare()
964
966
*/
965
967
 
966
968
int
967
 
my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b)
 
969
my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b)
968
970
{
969
971
  uint64_t a_t= TIME_to_uint64_t_datetime(a);
970
972
  uint64_t b_t= TIME_to_uint64_t_datetime(b);