Eneboo - Documentación para desarrolladores
src/libmysql_std/include/my_time.h
Ir a la documentación de este archivo.
00001 /* Copyright (C) 2004-2005 MySQL AB
00002 
00003  This program is free software; you can redistribute it and/or modify
00004  it under the terms of the GNU General Public License as published by
00005  the Free Software Foundation; version 2 of the License.
00006 
00007  This program is distributed in the hope that it will be useful,
00008  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  GNU General Public License for more details.
00011 
00012  You should have received a copy of the GNU General Public License
00013  along with this program; if not, write to the Free Software
00014  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00015 
00016 /*
00017   This is a private header of sql-common library, containing
00018   declarations for my_time.c
00019 */
00020 
00021 #ifndef _my_time_h_
00022 #define _my_time_h_
00023 #include "my_global.h"
00024 #include "mysql_time.h"
00025 
00026 C_MODE_START
00027 
00028 extern ulonglong log_10_int[20];
00029 extern uchar days_in_month[];
00030 
00031 /*
00032   Portable time_t replacement.
00033   Should be signed and hold seconds for 1902 -- 2038-01-19 range
00034   i.e at least a 32bit variable
00035 
00036   Using the system built in time_t is not an option as
00037   we rely on the above requirements in the time functions
00038 
00039   For example QNX has an unsigned time_t type
00040 */
00041 typedef long my_time_t;
00042 
00043 #define MY_TIME_T_MAX LONG_MAX
00044 #define MY_TIME_T_MIN LONG_MIN
00045 
00046 
00047 /* Time handling defaults */
00048 #define TIMESTAMP_MAX_YEAR 2038
00049 #define YY_PART_YEAR       70
00050 #define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
00051 #define TIMESTAMP_MAX_VALUE INT_MAX32
00052 #define TIMESTAMP_MIN_VALUE 1
00053 
00054 #define YY_PART_YEAR       70
00055 
00056 /* Flags to str_to_datetime */
00057 #define TIME_FUZZY_DATE         1
00058 #define TIME_DATETIME_ONLY      2
00059 /* Must be same as MODE_NO_ZERO_IN_DATE */
00060 #define TIME_NO_ZERO_IN_DATE    (65536L*2*2*2*2*2*2*2)
00061 /* Must be same as MODE_NO_ZERO_DATE */
00062 #define TIME_NO_ZERO_DATE       (TIME_NO_ZERO_IN_DATE*2)
00063 #define TIME_INVALID_DATES      (TIME_NO_ZERO_DATE*2)
00064 
00065 #define MYSQL_TIME_WARN_TRUNCATED    1
00066 #define MYSQL_TIME_WARN_OUT_OF_RANGE 2
00067 
00068 /* Limits for the TIME data type */
00069 #define TIME_MAX_HOUR 838
00070 #define TIME_MAX_MINUTE 59
00071 #define TIME_MAX_SECOND 59
00072 #define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \
00073                         TIME_MAX_SECOND)
00074 
00075 my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date,
00076                    ulong flags, int *was_cut);
00077 enum enum_mysql_timestamp_type
00078 str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
00079                 uint flags, int *was_cut);
00080 longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
00081                             uint flags, int *was_cut);
00082 ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *);
00083 ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *);
00084 ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *);
00085 ulonglong TIME_to_ulonglong(const MYSQL_TIME *);
00086 
00087 
00088 my_bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time,
00089                     int *warning);
00090 
00091 int check_time_range(struct st_mysql_time *, int *warning);
00092 
00093 long calc_daynr(uint year,uint month,uint day);
00094 uint calc_days_in_year(uint year);
00095 uint year_2000_handling(uint year);
00096 
00097 void init_time(void);
00098 
00099 
00100 /*
00101   Function to check sanity of a TIMESTAMP value
00102 
00103   DESCRIPTION
00104     Check if a given MYSQL_TIME value fits in TIMESTAMP range.
00105     This function doesn't make precise check, but rather a rough
00106     estimate.
00107 
00108   RETURN VALUES
00109     FALSE   The value seems sane
00110     TRUE    The MYSQL_TIME value is definitely out of range
00111 */
00112 
00113 static inline bool validate_timestamp_range(const MYSQL_TIME *t)
00114 {
00115   if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
00116       (t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
00117       (t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31)))
00118     return FALSE;
00119 
00120   return TRUE;
00121 }
00122 
00123 my_time_t 
00124 my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone,
00125                   my_bool *in_dst_time_gap);
00126 
00127 void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type);
00128 
00129 /*
00130   Required buffer length for my_time_to_str, my_date_to_str,
00131   my_datetime_to_str and TIME_to_string functions. Note, that the
00132   caller is still responsible to check that given TIME structure
00133   has values in valid ranges, otherwise size of the buffer could
00134   be not enough. We also rely on the fact that even wrong values
00135   sent using binary protocol fit in this buffer.
00136 */
00137 #define MAX_DATE_STRING_REP_LENGTH 30
00138 
00139 int my_time_to_str(const MYSQL_TIME *l_time, char *to);
00140 int my_date_to_str(const MYSQL_TIME *l_time, char *to);
00141 int my_datetime_to_str(const MYSQL_TIME *l_time, char *to);
00142 int my_TIME_to_str(const MYSQL_TIME *l_time, char *to);
00143 
00144 C_MODE_END
00145 
00146 #endif /* _my_time_h_ */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'