~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/time.cc

  • Committer: Monty Taylor
  • Date: 2008-07-13 21:27:17 UTC
  • mto: (77.4.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 153.
  • Revision ID: monty@inaugust.com-20080713212717-8r4dap6oqxopxrd6
Cleanup to hello_world Makefile.am

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