diff options
Diffstat (limited to 'include/my_time.h')
-rw-r--r-- | include/my_time.h | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/include/my_time.h b/include/my_time.h index 8ebca27e88d..c085797a161 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -47,11 +47,24 @@ typedef long my_time_t; #define TIMESTAMP_MAX_YEAR 2038 #define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1) #define TIMESTAMP_MAX_VALUE INT_MAX32 -#define TIMESTAMP_MIN_VALUE 1 +#define TIMESTAMP_MIN_VALUE 0 /* two-digit years < this are 20..; >= this are 19.. */ #define YY_PART_YEAR 70 +/* + check for valid times only if the range of time_t is greater than + the range of my_time_t +*/ +#if SIZEOF_TIME_T > 4 || defined(TIME_T_UNSIGNED) +# define IS_TIME_T_VALID_FOR_TIMESTAMP(x) \ + ((x) <= TIMESTAMP_MAX_VALUE && \ + (x) >= TIMESTAMP_MIN_VALUE) +#else +# define IS_TIME_T_VALID_FOR_TIMESTAMP(x) \ + ((x) >= TIMESTAMP_MIN_VALUE) +#endif + /* Flags to str_to_datetime */ #define TIME_FUZZY_DATE 1 #define TIME_DATETIME_ONLY 2 @@ -73,20 +86,24 @@ typedef long my_time_t; #define TIME_SECOND_PART_FACTOR (TIME_MAX_SECOND_PART+1) #define TIME_SECOND_PART_DIGITS 6 #define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \ - TIME_MAX_SECOND + TIME_MAX_SECOND_PART/(double)TIME_SECOND_PART_FACTOR) + TIME_MAX_SECOND + \ + TIME_MAX_SECOND_PART/(double)TIME_SECOND_PART_FACTOR) #define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \ TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND) my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, ulong flags, int *was_cut); enum enum_mysql_timestamp_type -str_to_time(const char *str, uint length, MYSQL_TIME *l_time, int *warning); +str_to_time(const char *str, uint length, MYSQL_TIME *l_time, + ulong flag, int *warning); enum enum_mysql_timestamp_type str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, - uint flags, int *was_cut); + ulong flags, int *was_cut); longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, uint flags, int *was_cut); int number_to_time(double nr, MYSQL_TIME *ltime, int *was_cut); +my_bool double_to_datetime(double nr, MYSQL_TIME *time_res, + uint flags); ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *); @@ -145,20 +162,20 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); #define MAX_DATE_STRING_REP_LENGTH 30 #define AUTO_SEC_PART_DIGITS 31 /* same as NOT_FIXED_DEC */ -int my_time_to_str(const MYSQL_TIME *l_time, char *to, int digits); +int my_time_to_str(const MYSQL_TIME *l_time, char *to, uint digits); int my_date_to_str(const MYSQL_TIME *l_time, char *to); -int my_datetime_to_str(const MYSQL_TIME *l_time, char *to, int digits); -int my_TIME_to_str(const MYSQL_TIME *l_time, char *to, int digits); +int my_datetime_to_str(const MYSQL_TIME *l_time, char *to, uint digits); +int my_TIME_to_str(const MYSQL_TIME *l_time, char *to, uint digits); -static inline longlong sec_part_shift(longlong second_part, int digits) +static inline longlong sec_part_shift(longlong second_part, uint digits) { return second_part / (longlong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; } -static inline longlong sec_part_unshift(longlong second_part, int digits) +static inline longlong sec_part_unshift(longlong second_part, uint digits) { return second_part * (longlong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; } -static inline ulong sec_part_truncate(ulong second_part, int digits) +static inline ulong sec_part_truncate(ulong second_part, uint digits) { /* the cast here should be unnecessary! */ return second_part - second_part % (ulong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; |