14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
#include <my_time.h>
17
#include <mystrings/m_string.h>
18
#include <mystrings/m_ctype.h>
19
#include <drizzled/util/test.h>
20
19
/* Windows version of localtime_r() is declared in my_ptrhead.h */
20
#include <my_pthread.h>
22
uint64_t log_10_int[20]=
22
ulonglong log_10_int[20]=
24
24
1, 10, 100, 1000, 10000UL, 100000UL, 1000000UL, 10000000UL,
25
100000000ULL, 1000000000ULL, 10000000000ULL, 100000000000ULL,
26
1000000000000ULL, 10000000000000ULL, 100000000000000ULL,
27
1000000000000000ULL, 10000000000000000ULL, 100000000000000000ULL,
28
1000000000000000000ULL, 10000000000000000000ULL
25
ULL(100000000), ULL(1000000000), ULL(10000000000), ULL(100000000000),
26
ULL(1000000000000), ULL(10000000000000), ULL(100000000000000),
27
ULL(1000000000000000), ULL(10000000000000000), ULL(100000000000000000),
28
ULL(1000000000000000000), ULL(10000000000000000000)
32
32
/* Position for YYYY-DD-MM HH-MM-DD.FFFFFF AM in default format */
34
static unsigned char internal_format_positions[]=
35
{0, 1, 2, 3, 4, 5, 6, (unsigned char) 255};
34
static uchar internal_format_positions[]=
35
{0, 1, 2, 3, 4, 5, 6, (uchar) 255};
37
37
static char time_separator=':';
39
static uint32_t const days_at_timestart=719528; /* daynr at 1970.01.01 */
40
unsigned char days_in_month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
39
static ulong const days_at_timestart=719528; /* daynr at 1970.01.01 */
40
uchar days_in_month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
43
43
Offset of system time zone from UTC in seconds used to speed up
145
145
- The hour part must be specified in hour-minute-second order.
148
DRIZZLE_TIMESTAMP_NONE String wasn't a timestamp, like
148
MYSQL_TIMESTAMP_NONE String wasn't a timestamp, like
149
149
[DD [HH:[MM:[SS]]]].fraction.
150
150
l_time is not changed.
151
DRIZZLE_TIMESTAMP_DATE DATE string (YY MM and DD parts ok)
152
DRIZZLE_TIMESTAMP_DATETIME Full timestamp
153
DRIZZLE_TIMESTAMP_ERROR Timestamp with wrong values.
151
MYSQL_TIMESTAMP_DATE DATE string (YY MM and DD parts ok)
152
MYSQL_TIMESTAMP_DATETIME Full timestamp
153
MYSQL_TIMESTAMP_ERROR Timestamp with wrong values.
154
154
All elements in l_time is set to 0
157
157
#define MAX_DATE_PARTS 8
159
enum enum_drizzle_timestamp_type
160
str_to_datetime(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
161
uint32_t flags, int *was_cut)
159
enum enum_mysql_timestamp_type
160
str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
161
uint flags, int *was_cut)
163
uint32_t field_length, year_length=4, digits, i, number_of_fields;
164
uint32_t date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS];
165
uint32_t add_hours= 0, start_loop;
166
uint32_t not_zero_date, allow_space;
167
bool is_internal_format;
168
const char *pos, *last_field_pos=NULL;
163
uint field_length, year_length, digits, i, number_of_fields;
164
uint date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS];
165
uint add_hours= 0, start_loop;
166
ulong not_zero_date, allow_space;
167
my_bool is_internal_format;
168
const char *pos, *last_field_pos;
169
169
const char *end=str+length;
170
const unsigned char *format_position;
171
bool found_delimitier= 0, found_space= 0;
172
uint32_t frac_pos, frac_len;
170
const uchar *format_position;
171
my_bool found_delimitier= 0, found_space= 0;
172
uint frac_pos, frac_len;
173
DBUG_ENTER("str_to_datetime");
174
DBUG_PRINT("ENTER",("str: %.*s",length,str));
176
178
/* Skip space at start */
177
for (; str != end && my_isspace(&my_charset_utf8_general_ci, *str) ; str++)
179
for (; str != end && my_isspace(&my_charset_latin1, *str) ; str++)
179
if (str == end || ! my_isdigit(&my_charset_utf8_general_ci, *str))
181
if (str == end || ! my_isdigit(&my_charset_latin1, *str))
182
return(DRIZZLE_TIMESTAMP_NONE);
184
DBUG_RETURN(MYSQL_TIMESTAMP_NONE);
185
187
is_internal_format= 0;
217
219
We do this by checking if there is two numbers separated by
218
220
space in the input.
220
while (pos < end && !my_isspace(&my_charset_utf8_general_ci, *pos))
222
while (pos < end && !my_isspace(&my_charset_latin1, *pos))
222
while (pos < end && !my_isdigit(&my_charset_utf8_general_ci, *pos))
224
while (pos < end && !my_isdigit(&my_charset_latin1, *pos))
226
228
if (flags & TIME_DATETIME_ONLY)
229
return(DRIZZLE_TIMESTAMP_NONE); /* Can't be a full datetime */
231
DBUG_RETURN(MYSQL_TIMESTAMP_NONE); /* Can't be a full datetime */
231
233
/* Date field. Set hour, minutes and seconds to 0 */
232
234
date[0]= date[1]= date[2]= date[3]= date[4]= 0;
253
255
not_zero_date= 0;
254
256
for (i = start_loop;
255
257
i < MAX_DATE_PARTS-1 && str != end &&
256
my_isdigit(&my_charset_utf8_general_ci,*str);
258
my_isdigit(&my_charset_latin1,*str);
259
261
const char *start= str;
260
uint32_t tmp_value= (uint) (unsigned char) (*str++ - '0');
261
while (str != end && my_isdigit(&my_charset_utf8_general_ci,str[0]) &&
262
ulong tmp_value= (uint) (uchar) (*str++ - '0');
263
while (str != end && my_isdigit(&my_charset_latin1,str[0]) &&
262
264
(!is_internal_format || --field_length))
264
tmp_value=tmp_value*10 + (uint32_t) (unsigned char) (*str - '0');
266
tmp_value=tmp_value*10 + (ulong) (uchar) (*str - '0');
267
269
date_len[i]= (uint) (str - start);
268
270
if (tmp_value > 999999) /* Impossible date part */
271
return(DRIZZLE_TIMESTAMP_NONE);
273
DBUG_RETURN(MYSQL_TIMESTAMP_NONE);
273
275
date[i]=tmp_value;
274
276
not_zero_date|= tmp_value;
299
301
while (str != end &&
300
(my_ispunct(&my_charset_utf8_general_ci,*str) ||
301
my_isspace(&my_charset_utf8_general_ci,*str)))
302
(my_ispunct(&my_charset_latin1,*str) ||
303
my_isspace(&my_charset_latin1,*str)))
303
if (my_isspace(&my_charset_utf8_general_ci,*str))
305
if (my_isspace(&my_charset_latin1,*str))
305
307
if (!(allow_space & (1 << i)))
308
return(DRIZZLE_TIMESTAMP_NONE);
310
DBUG_RETURN(MYSQL_TIMESTAMP_NONE);
424
426
l_time->time_type= (number_of_fields <= 3 ?
425
DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME);
427
MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME);
427
429
for (; str != end ; str++)
429
if (!my_isspace(&my_charset_utf8_general_ci,*str))
431
if (!my_isspace(&my_charset_latin1,*str))
436
return(l_time->time_type=
437
(number_of_fields <= 3 ? DRIZZLE_TIMESTAMP_DATE :
438
DRIZZLE_TIMESTAMP_DATETIME));
438
DBUG_RETURN(l_time->time_type=
439
(number_of_fields <= 3 ? MYSQL_TIMESTAMP_DATE :
440
MYSQL_TIMESTAMP_DATETIME));
441
memset(l_time, 0, sizeof(*l_time));
442
return(DRIZZLE_TIMESTAMP_ERROR);
443
bzero((char*) l_time, sizeof(*l_time));
444
DBUG_RETURN(MYSQL_TIMESTAMP_ERROR);
447
Convert a time string to a DRIZZLE_TIME struct.
449
Convert a time string to a MYSQL_TIME struct.
471
bool str_to_time(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
473
my_bool str_to_time(const char *str, uint length, MYSQL_TIME *l_time,
476
478
const char *end=str+length, *end_of_days;
477
bool found_days,found_hours;
479
my_bool found_days,found_hours;
482
for (; str != end && my_isspace(&my_charset_utf8_general_ci,*str) ; str++)
484
for (; str != end && my_isspace(&my_charset_latin1,*str) ; str++)
484
486
if (str != end && *str == '-')
494
496
if (length >= 12)
495
497
{ /* Probably full timestamp */
497
enum enum_drizzle_timestamp_type
499
enum enum_mysql_timestamp_type
498
500
res= str_to_datetime(str, length, l_time,
499
501
(TIME_FUZZY_DATE | TIME_DATETIME_ONLY), &was_cut);
500
if ((int) res >= (int) DRIZZLE_TIMESTAMP_ERROR)
502
if ((int) res >= (int) MYSQL_TIMESTAMP_ERROR)
503
*warning|= DRIZZLE_TIME_WARN_TRUNCATED;
504
return res == DRIZZLE_TIMESTAMP_ERROR;
505
*warning|= MYSQL_TIME_WARN_TRUNCATED;
506
return res == MYSQL_TIMESTAMP_ERROR;
508
510
/* Not a timestamp. Try to get this as a DAYS_TO_SECOND string */
509
for (value=0; str != end && my_isdigit(&my_charset_utf8_general_ci,*str) ; str++)
511
for (value=0; str != end && my_isdigit(&my_charset_latin1,*str) ; str++)
510
512
value=value*10L + (long) (*str - '0');
512
514
/* Skip all space after 'days' */
513
515
end_of_days= str;
514
for (; str != end && my_isspace(&my_charset_utf8_general_ci, str[0]) ; str++)
516
for (; str != end && my_isspace(&my_charset_latin1, str[0]) ; str++)
517
519
found_days=found_hours=0;
518
520
if ((uint) (end-str) > 1 && str != end_of_days &&
519
my_isdigit(&my_charset_utf8_general_ci, *str))
521
my_isdigit(&my_charset_latin1, *str))
520
522
{ /* Found days part */
521
date[0]= (uint32_t) value;
523
date[0]= (ulong) value;
522
524
state= 1; /* Assume next is hours */
525
527
else if ((end-str) > 1 && *str == time_separator &&
526
my_isdigit(&my_charset_utf8_general_ci, str[1]))
528
my_isdigit(&my_charset_latin1, str[1]))
528
530
date[0]= 0; /* Assume we found hours */
529
date[1]= (uint32_t) value;
531
date[1]= (ulong) value;
532
534
str++; /* skip ':' */
545
547
/* Read hours, minutes and seconds */
548
for (value=0; str != end && my_isdigit(&my_charset_utf8_general_ci,*str) ; str++)
550
for (value=0; str != end && my_isdigit(&my_charset_latin1,*str) ; str++)
549
551
value=value*10L + (long) (*str - '0');
550
date[state++]= (uint32_t) value;
552
date[state++]= (ulong) value;
551
553
if (state == 4 || (end-str) < 2 || *str != time_separator ||
552
!my_isdigit(&my_charset_utf8_general_ci,str[1]))
554
!my_isdigit(&my_charset_latin1,str[1]))
554
556
str++; /* Skip time_separator (':') */
559
561
/* Fix the date to assume that seconds was given */
560
562
if (!found_hours && !found_days)
562
bmove_upp((unsigned char*) (date+4), (unsigned char*) (date+state),
564
bmove_upp((uchar*) (date+4), (uchar*) (date+state),
563
565
sizeof(long)*(state-1));
564
memset(date, 0, sizeof(long)*(4-state));
566
bzero((uchar*) date, sizeof(long)*(4-state));
567
memset(date+state, 0, sizeof(long)*(4-state));
569
bzero((uchar*) (date+state), sizeof(long)*(4-state));
571
573
/* Get fractional second part */
572
if ((end-str) >= 2 && *str == '.' && my_isdigit(&my_charset_utf8_general_ci,str[1]))
574
if ((end-str) >= 2 && *str == '.' && my_isdigit(&my_charset_latin1,str[1]))
574
576
int field_length= 5;
575
str++; value=(uint) (unsigned char) (*str - '0');
576
while (++str != end && my_isdigit(&my_charset_utf8_general_ci, *str))
577
str++; value=(uint) (uchar) (*str - '0');
578
while (++str != end && my_isdigit(&my_charset_latin1, *str))
578
580
if (field_length-- > 0)
579
value= value*10 + (uint) (unsigned char) (*str - '0');
581
value= value*10 + (uint) (uchar) (*str - '0');
581
583
if (field_length > 0)
582
584
value*= (long) log_10_int[field_length];
583
585
else if (field_length < 0)
584
*warning|= DRIZZLE_TIME_WARN_TRUNCATED;
585
date[4]= (uint32_t) value;
586
*warning|= MYSQL_TIME_WARN_TRUNCATED;
587
date[4]= (ulong) value;
591
593
/* (may occur as result of %g formatting of time value) */
592
594
if ((end - str) > 1 &&
593
595
(*str == 'e' || *str == 'E') &&
594
(my_isdigit(&my_charset_utf8_general_ci, str[1]) ||
596
(my_isdigit(&my_charset_latin1, str[1]) ||
595
597
((str[1] == '-' || str[1] == '+') &&
596
598
(end - str) > 2 &&
597
my_isdigit(&my_charset_utf8_general_ci, str[2]))))
599
my_isdigit(&my_charset_latin1, str[2]))))
600
602
if (internal_format_positions[7] != 255)
602
604
/* Read a possible AM/PM */
603
while (str != end && my_isspace(&my_charset_utf8_general_ci, *str))
605
while (str != end && my_isspace(&my_charset_latin1, *str))
605
607
if (str+2 <= end && (str[1] == 'M' || str[1] == 'm'))
627
629
l_time->minute= date[2];
628
630
l_time->second= date[3];
629
631
l_time->second_part= date[4];
630
l_time->time_type= DRIZZLE_TIMESTAMP_TIME;
632
l_time->time_type= MYSQL_TIMESTAMP_TIME;
632
/* Check if the value is valid and fits into DRIZZLE_TIME range */
634
/* Check if the value is valid and fits into MYSQL_TIME range */
633
635
if (check_time_range(l_time, warning))
636
/* Check if there is garbage at end of the DRIZZLE_TIME specification */
638
/* Check if there is garbage at end of the MYSQL_TIME specification */
641
if (!my_isspace(&my_charset_utf8_general_ci,*str))
643
if (!my_isspace(&my_charset_latin1,*str))
643
*warning|= DRIZZLE_TIME_WARN_TRUNCATED;
645
*warning|= MYSQL_TIME_WARN_TRUNCATED;
646
648
} while (++str != end);
653
Check 'time' value to lie in the DRIZZLE_TIME range
655
Check 'time' value to lie in the MYSQL_TIME range
656
658
check_time_range()
657
time pointer to DRIZZLE_TIME value
658
warning set DRIZZLE_TIME_WARN_OUT_OF_RANGE flag if the value is out of range
659
time pointer to MYSQL_TIME value
660
warning set MYSQL_TIME_WARN_OUT_OF_RANGE flag if the value is out of range
661
663
If the time value lies outside of the range [-838:59:59, 838:59:59],
662
664
set it to the closest endpoint of the range and set
663
DRIZZLE_TIME_WARN_OUT_OF_RANGE flag in the 'warning' variable.
665
MYSQL_TIME_WARN_OUT_OF_RANGE flag in the 'warning' variable.
666
668
0 time value is valid, but was possibly truncated
667
669
1 time value is invalid
670
int check_time_range(DRIZZLE_TIME *my_time, int *warning)
672
int check_time_range(struct st_mysql_time *my_time, int *warning)
674
676
if (my_time->minute >= 60 || my_time->second >= 60)
751
753
Days since 0000-00-00
754
long calc_daynr(uint32_t year,uint32_t month,uint32_t day)
756
long calc_daynr(uint year,uint month,uint day)
760
DBUG_ENTER("calc_daynr");
759
762
if (year == 0 && month == 0 && day == 0)
760
return(0); /* Skip errors */
763
DBUG_RETURN(0); /* Skip errors */
761
764
delsum= (long) (365L * year+ 31*(month-1) +day);
765
768
delsum-= (long) (month*4+23)/10;
766
769
temp=(int) ((year/100+1)*3)/4;
767
return(delsum+(int) year/4-temp);
770
DBUG_PRINT("exit",("year: %d month: %d day: %d -> daynr: %ld",
771
year+(month <= 2),month,day,delsum+year/4-temp));
772
DBUG_RETURN(delsum+(int) year/4-temp);
768
773
} /* calc_daynr */
772
Convert time in DRIZZLE_TIME representation in system time zone to its
777
Convert time in MYSQL_TIME representation in system time zone to its
773
778
my_time_t form (number of seconds in UTC since begginning of Unix Epoch).
791
796
Time in UTC seconds since Unix Epoch representation.
794
my_system_gmt_sec(const DRIZZLE_TIME *t_src, long *my_timezone,
795
bool *in_dst_time_gap)
799
my_system_gmt_sec(const MYSQL_TIME *t_src, long *my_timezone,
800
my_bool *in_dst_time_gap)
800
DRIZZLE_TIME tmp_time;
801
DRIZZLE_TIME *t= &tmp_time;
806
MYSQL_TIME *t= &tmp_time;
802
807
struct tm *l_time,tm_tmp;
803
808
long diff, current_timezone;
980
985
} /* my_system_gmt_sec */
983
/* Set DRIZZLE_TIME structure to 0000-00-00 00:00:00.000000 */
988
/* Set MYSQL_TIME structure to 0000-00-00 00:00:00.000000 */
985
void set_zero_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type time_type)
990
void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type)
987
memset(tm, 0, sizeof(*tm));
992
bzero((void*) tm, sizeof(*tm));
988
993
tm->time_type= time_type;
1002
1007
number of characters written to 'to'
1005
int my_time_to_str(const DRIZZLE_TIME *l_time, char *to)
1010
int my_time_to_str(const MYSQL_TIME *l_time, char *to)
1007
uint32_t extra_hours= 0;
1008
return sprintf(to, "%s%02u:%02u:%02u",
1012
uint extra_hours= 0;
1013
return my_sprintf(to, (to, "%s%02u:%02u:%02u",
1009
1014
(l_time->neg ? "-" : ""),
1010
1015
extra_hours+ l_time->hour,
1011
1016
l_time->minute,
1015
int my_date_to_str(const DRIZZLE_TIME *l_time, char *to)
1020
int my_date_to_str(const MYSQL_TIME *l_time, char *to)
1017
return sprintf(to, "%04u-%02u-%02u",
1022
return my_sprintf(to, (to, "%04u-%02u-%02u",
1023
int my_datetime_to_str(const DRIZZLE_TIME *l_time, char *to)
1028
int my_datetime_to_str(const MYSQL_TIME *l_time, char *to)
1025
return sprintf(to, "%04u-%02u-%02u %02u:%02u:%02u",
1030
return my_sprintf(to, (to, "%04u-%02u-%02u %02u:%02u:%02u",
1030
1035
l_time->minute,
1043
1048
The string must have at least MAX_DATE_STRING_REP_LENGTH bytes reserved.
1046
int my_TIME_to_str(const DRIZZLE_TIME *l_time, char *to)
1051
int my_TIME_to_str(const MYSQL_TIME *l_time, char *to)
1048
1053
switch (l_time->time_type) {
1049
case DRIZZLE_TIMESTAMP_DATETIME:
1054
case MYSQL_TIMESTAMP_DATETIME:
1050
1055
return my_datetime_to_str(l_time, to);
1051
case DRIZZLE_TIMESTAMP_DATE:
1056
case MYSQL_TIMESTAMP_DATE:
1052
1057
return my_date_to_str(l_time, to);
1053
case DRIZZLE_TIMESTAMP_TIME:
1058
case MYSQL_TIMESTAMP_TIME:
1054
1059
return my_time_to_str(l_time, to);
1055
case DRIZZLE_TIMESTAMP_NONE:
1056
case DRIZZLE_TIMESTAMP_ERROR:
1060
case MYSQL_TIMESTAMP_NONE:
1061
case MYSQL_TIMESTAMP_ERROR:
1089
1094
Datetime value in YYYYMMDDHHMMSS format.
1092
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res,
1093
uint32_t flags, int *was_cut)
1097
longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
1098
uint flags, int *was_cut)
1095
1100
long part1,part2;
1098
memset(time_res, 0, sizeof(*time_res));
1099
time_res->time_type=DRIZZLE_TIMESTAMP_DATE;
1103
bzero((char*) time_res, sizeof(*time_res));
1104
time_res->time_type=MYSQL_TIMESTAMP_DATE;
1101
if (nr == 0LL || nr >= 10000101000000LL)
1106
if (nr == LL(0) || nr >= LL(10000101000000))
1103
time_res->time_type=DRIZZLE_TIMESTAMP_DATETIME;
1108
time_res->time_type=MYSQL_TIMESTAMP_DATETIME;
1127
1132
if (nr < 101000000L)
1130
time_res->time_type=DRIZZLE_TIMESTAMP_DATETIME;
1135
time_res->time_type=MYSQL_TIMESTAMP_DATETIME;
1132
if (nr <= (YY_PART_YEAR-1) * 10000000000LL + 1231235959LL)
1137
if (nr <= (YY_PART_YEAR-1)*LL(10000000000)+LL(1231235959))
1134
nr= nr + 20000000000000LL; /* YYMMDDHHMMSS, 2000-2069 */
1139
nr= nr+LL(20000000000000); /* YYMMDDHHMMSS, 2000-2069 */
1137
if (nr < YY_PART_YEAR * 10000000000LL + 101000000LL)
1142
if (nr < YY_PART_YEAR*LL(10000000000)+ LL(101000000))
1139
if (nr <= 991231235959LL)
1140
nr= nr + 19000000000000LL; /* YYMMDDHHMMSS, 1970-1999 */
1144
if (nr <= LL(991231235959))
1145
nr= nr+LL(19000000000000); /* YYMMDDHHMMSS, 1970-1999 */
1143
part1=(long) (nr / 1000000LL);
1144
part2=(long) (nr - (int64_t) part1 * 1000000LL);
1148
part1=(long) (nr/LL(1000000));
1149
part2=(long) (nr - (longlong) part1*LL(1000000));
1145
1150
time_res->year= (int) (part1/10000L); part1%=10000L;
1146
1151
time_res->month= (int) part1 / 100;
1147
1152
time_res->day= (int) part1 % 100;
1158
1163
/* Don't want to have was_cut get set if NO_ZERO_DATE was violated. */
1159
1164
if (!nr && (flags & TIME_NO_ZERO_DATE))
1168
1173
/* Convert time value to integer in YYYYMMDDHHMMSS format */
1170
uint64_t TIME_to_uint64_t_datetime(const DRIZZLE_TIME *my_time)
1175
ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *my_time)
1172
return ((uint64_t) (my_time->year * 10000UL +
1177
return ((ulonglong) (my_time->year * 10000UL +
1173
1178
my_time->month * 100UL +
1174
my_time->day) * 1000000ULL +
1175
(uint64_t) (my_time->hour * 10000UL +
1179
my_time->day) * ULL(1000000) +
1180
(ulonglong) (my_time->hour * 10000UL +
1176
1181
my_time->minute * 100UL +
1177
1182
my_time->second));
1181
/* Convert DRIZZLE_TIME value to integer in YYYYMMDD format */
1186
/* Convert MYSQL_TIME value to integer in YYYYMMDD format */
1183
uint64_t TIME_to_uint64_t_date(const DRIZZLE_TIME *my_time)
1188
ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *my_time)
1185
return (uint64_t) (my_time->year * 10000UL + my_time->month * 100UL +
1190
return (ulonglong) (my_time->year * 10000UL + my_time->month * 100UL +
1191
Convert DRIZZLE_TIME value to integer in HHMMSS format.
1196
Convert MYSQL_TIME value to integer in HHMMSS format.
1192
1197
This function doesn't take into account time->day member:
1193
1198
it's assumed that days have been converted to hours already.
1196
uint64_t TIME_to_uint64_t_time(const DRIZZLE_TIME *my_time)
1201
ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *my_time)
1198
return (uint64_t) (my_time->hour * 10000UL +
1203
return (ulonglong) (my_time->hour * 10000UL +
1199
1204
my_time->minute * 100UL +
1200
1205
my_time->second);
1205
Convert struct DRIZZLE_TIME (date and time split into year/month/day/hour/...
1210
Convert struct MYSQL_TIME (date and time split into year/month/day/hour/...
1206
1211
to a number in format YYYYMMDDHHMMSS (DATETIME),
1207
1212
YYYYMMDD (DATE) or HHMMSS (TIME).
1213
1218
The function is used when we need to convert value of time item
1219
This function doesn't check that given DRIZZLE_TIME structure members are
1224
This function doesn't check that given MYSQL_TIME structure members are
1220
1225
in valid range. If they are not, return value won't reflect any
1221
1226
valid date either.
1224
uint64_t TIME_to_uint64_t(const DRIZZLE_TIME *my_time)
1229
ulonglong TIME_to_ulonglong(const MYSQL_TIME *my_time)
1226
1231
switch (my_time->time_type) {
1227
case DRIZZLE_TIMESTAMP_DATETIME:
1228
return TIME_to_uint64_t_datetime(my_time);
1229
case DRIZZLE_TIMESTAMP_DATE:
1230
return TIME_to_uint64_t_date(my_time);
1231
case DRIZZLE_TIMESTAMP_TIME:
1232
return TIME_to_uint64_t_time(my_time);
1233
case DRIZZLE_TIMESTAMP_NONE:
1234
case DRIZZLE_TIMESTAMP_ERROR:
1232
case MYSQL_TIMESTAMP_DATETIME:
1233
return TIME_to_ulonglong_datetime(my_time);
1234
case MYSQL_TIMESTAMP_DATE:
1235
return TIME_to_ulonglong_date(my_time);
1236
case MYSQL_TIMESTAMP_TIME:
1237
return TIME_to_ulonglong_time(my_time);
1238
case MYSQL_TIMESTAMP_NONE:
1239
case MYSQL_TIMESTAMP_ERROR: