23 #include "my_global.h"
24 #include "mysql_time.h"
28 extern ulonglong log_10_int[20];
29 extern uchar days_in_month[];
30 extern const char my_zero_datetime6[];
40 typedef long my_time_t;
42 #define MY_TIME_T_MAX LONG_MAX
43 #define MY_TIME_T_MIN LONG_MIN
45 #define DATETIME_MAX_DECIMALS 6
48 #define TIMESTAMP_MAX_YEAR 2038
49 #define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
50 #define TIMESTAMP_MAX_VALUE INT_MAX32
51 #define TIMESTAMP_MIN_VALUE 1
54 #define YY_PART_YEAR 70
60 #if SIZEOF_TIME_T > 4 || defined(TIME_T_UNSIGNED)
61 # define IS_TIME_T_VALID_FOR_TIMESTAMP(x) \
62 ((x) <= TIMESTAMP_MAX_VALUE && \
63 (x) >= TIMESTAMP_MIN_VALUE)
65 # define IS_TIME_T_VALID_FOR_TIMESTAMP(x) \
66 ((x) >= TIMESTAMP_MIN_VALUE)
70 #define TIME_FUZZY_DATE 1
71 #define TIME_DATETIME_ONLY 2
72 #define TIME_NO_NSEC_ROUNDING 4
73 #define TIME_NO_DATE_FRAC_WARN 8
76 #define TIME_NO_ZERO_IN_DATE (65536L*2*2*2*2*2*2*2)
78 #define TIME_NO_ZERO_DATE (TIME_NO_ZERO_IN_DATE*2)
79 #define TIME_INVALID_DATES (TIME_NO_ZERO_DATE*2)
82 #define MYSQL_TIME_WARN_TRUNCATED 1
83 #define MYSQL_TIME_WARN_OUT_OF_RANGE 2
84 #define MYSQL_TIME_WARN_INVALID_TIMESTAMP 4
85 #define MYSQL_TIME_WARN_ZERO_DATE 8
86 #define MYSQL_TIME_NOTE_TRUNCATED 16
87 #define MYSQL_TIME_WARN_ZERO_IN_DATE 32
90 #define SECONDS_IN_24H 86400L
93 #define TIME_MAX_HOUR 838
94 #define TIME_MAX_MINUTE 59
95 #define TIME_MAX_SECOND 59
96 #define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \
98 #define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \
99 TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
108 uint fractional_digits;
114 status->warnings= status->fractional_digits= status->nanoseconds= 0;
118 my_bool check_date(
const MYSQL_TIME *ltime, my_bool not_zero_date,
119 ulonglong
flags,
int *was_cut);
120 my_bool str_to_datetime(
const char *str, uint length,
MYSQL_TIME *l_time,
122 longlong number_to_datetime(longlong nr,
MYSQL_TIME *time_res,
123 ulonglong
flags,
int *was_cut);
124 my_bool number_to_time(longlong nr,
MYSQL_TIME *ltime,
int *warnings);
125 ulonglong TIME_to_ulonglong_datetime(
const MYSQL_TIME *);
126 ulonglong TIME_to_ulonglong_date(
const MYSQL_TIME *);
127 ulonglong TIME_to_ulonglong_time(
const MYSQL_TIME *);
128 ulonglong TIME_to_ulonglong(
const MYSQL_TIME *);
130 #define MY_PACKED_TIME_GET_INT_PART(x) ((x) >> 24)
131 #define MY_PACKED_TIME_GET_FRAC_PART(x) ((x) % (1LL << 24))
132 #define MY_PACKED_TIME_MAKE(i, f) ((((longlong) (i)) << 24) + (f))
133 #define MY_PACKED_TIME_MAKE_INT(i) ((((longlong) (i)) << 24))
135 longlong year_to_longlong_datetime_packed(
long year);
136 longlong TIME_to_longlong_datetime_packed(
const MYSQL_TIME *);
137 longlong TIME_to_longlong_date_packed(
const MYSQL_TIME *);
138 longlong TIME_to_longlong_time_packed(
const MYSQL_TIME *);
139 longlong TIME_to_longlong_packed(
const MYSQL_TIME *);
141 void TIME_from_longlong_datetime_packed(
MYSQL_TIME *ltime, longlong nr);
142 void TIME_from_longlong_time_packed(
MYSQL_TIME *ltime, longlong nr);
143 void TIME_from_longlong_date_packed(
MYSQL_TIME *ltime, longlong nr);
144 void TIME_set_yymmdd(
MYSQL_TIME *ltime, uint yymmdd);
145 void TIME_set_hhmmss(
MYSQL_TIME *ltime, uint hhmmss);
147 void my_datetime_packed_to_binary(longlong nr, uchar *ptr, uint dec);
148 longlong my_datetime_packed_from_binary(
const uchar *ptr, uint dec);
149 uint my_datetime_binary_length(uint dec);
151 void my_time_packed_to_binary(longlong nr, uchar *ptr, uint dec);
152 longlong my_time_packed_from_binary(
const uchar *ptr, uint dec);
153 uint my_time_binary_length(uint dec);
155 void my_timestamp_to_binary(
const struct timeval *tm, uchar *ptr, uint dec);
156 void my_timestamp_from_binary(
struct timeval *tm,
const uchar *ptr, uint dec);
157 uint my_timestamp_binary_length(uint dec);
159 my_bool str_to_time(
const char *str,uint length,
MYSQL_TIME *l_time,
162 my_bool check_time_mmssff_range(
const MYSQL_TIME *ltime);
163 my_bool check_time_range_quick(
const MYSQL_TIME *ltime);
164 my_bool check_datetime_range(
const MYSQL_TIME *ltime);
165 void adjust_time_range(
struct st_mysql_time *,
int *warning);
167 long calc_daynr(uint year,uint month,uint day);
168 uint calc_days_in_year(uint year);
169 uint year_2000_handling(uint year);
171 void my_init_time(
void);
187 static inline my_bool validate_timestamp_range(
const MYSQL_TIME *t)
189 if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
190 (t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
191 (t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31)))
198 my_system_gmt_sec(
const MYSQL_TIME *t,
long *my_timezone,
199 my_bool *in_dst_time_gap);
201 void set_zero_time(
MYSQL_TIME *tm,
enum enum_mysql_timestamp_type time_type);
202 void set_max_time(
MYSQL_TIME *tm, my_bool neg);
213 #define MAX_DATE_STRING_REP_LENGTH 30
215 int my_time_to_str(
const MYSQL_TIME *l_time,
char *
to, uint dec);
217 int my_datetime_to_str(
const MYSQL_TIME *l_time,
char *
to, uint dec);
218 int my_TIME_to_str(
const MYSQL_TIME *l_time,
char *
to, uint dec);
220 int my_timeval_to_str(
const struct timeval *tm,
char *
to, uint dec);
239 INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_WEEK, INTERVAL_DAY,
240 INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND, INTERVAL_MICROSECOND,
241 INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE,
242 INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND,
243 INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND,
244 INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND, INTERVAL_LAST