236.1.23
by Monty Taylor
Cleaned header headers. |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 MySQL
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
1
by brian
clean slate |
20 |
|
21 |
/*
|
|
22 |
This is a private header of sql-common library, containing
|
|
23 |
declarations for my_time.c
|
|
24 |
*/
|
|
25 |
||
236.1.23
by Monty Taylor
Cleaned header headers. |
26 |
#ifndef _libdrizzle_my_time_h_
|
27 |
#define _libdrizzle_my_time_h_
|
|
28 |
||
212.5.39
by Monty Taylor
Phew. Moved my_base and my_global. |
29 |
#include "drizzled/global.h" |
77.1.39
by Monty Taylor
More mysql->drizzle renaming. |
30 |
#include "drizzle_time.h" |
1
by brian
clean slate |
31 |
|
32 |
C_MODE_START
|
|
33 |
||
151
by Brian Aker
Ulonglong to uint64_t |
34 |
extern uint64_t log_10_int[20]; |
1
by brian
clean slate |
35 |
extern uchar days_in_month[]; |
36 |
||
37 |
/*
|
|
38 |
Portable time_t replacement.
|
|
39 |
Should be signed and hold seconds for 1902 -- 2038-01-19 range
|
|
40 |
i.e at least a 32bit variable
|
|
41 |
||
42 |
Using the system built in time_t is not an option as
|
|
43 |
we rely on the above requirements in the time functions
|
|
44 |
||
45 |
For example QNX has an unsigned time_t type
|
|
46 |
*/
|
|
47 |
typedef long my_time_t; |
|
48 |
||
163
by Brian Aker
Merge Monty's code. |
49 |
#define MY_TIME_T_MAX INT32_MAX
|
50 |
#define MY_TIME_T_MIN INT32_MIN
|
|
1
by brian
clean slate |
51 |
|
52 |
/* Time handling defaults */
|
|
53 |
#define TIMESTAMP_MAX_YEAR 2038
|
|
54 |
#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
|
|
163
by Brian Aker
Merge Monty's code. |
55 |
#define TIMESTAMP_MAX_VALUE INT32_MAX
|
1
by brian
clean slate |
56 |
#define TIMESTAMP_MIN_VALUE 1
|
57 |
||
58 |
/* two-digit years < this are 20..; >= this are 19.. */
|
|
59 |
#define YY_PART_YEAR 70
|
|
60 |
||
61 |
/* Flags to str_to_datetime */
|
|
62 |
#define TIME_FUZZY_DATE 1
|
|
63 |
#define TIME_DATETIME_ONLY 2
|
|
64 |
/* Must be same as MODE_NO_ZERO_IN_DATE */
|
|
65 |
#define TIME_NO_ZERO_IN_DATE (65536L*2*2*2*2*2*2*2)
|
|
66 |
/* Must be same as MODE_NO_ZERO_DATE */
|
|
67 |
#define TIME_NO_ZERO_DATE (TIME_NO_ZERO_IN_DATE*2)
|
|
68 |
#define TIME_INVALID_DATES (TIME_NO_ZERO_DATE*2)
|
|
69 |
||
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
70 |
#define DRIZZLE_TIME_WARN_TRUNCATED 1
|
71 |
#define DRIZZLE_TIME_WARN_OUT_OF_RANGE 2
|
|
1
by brian
clean slate |
72 |
|
73 |
/* Limits for the TIME data type */
|
|
74 |
#define TIME_MAX_HOUR 838
|
|
75 |
#define TIME_MAX_MINUTE 59
|
|
76 |
#define TIME_MAX_SECOND 59
|
|
77 |
#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \
|
|
78 |
TIME_MAX_SECOND)
|
|
79 |
#define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \
|
|
80 |
TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
|
|
81 |
||
236.1.26
by Monty Taylor
my_bool cleanup in libdrizzle time stuff. |
82 |
bool check_date(const DRIZZLE_TIME *ltime, bool not_zero_date, |
1
by brian
clean slate |
83 |
ulong flags, int *was_cut); |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
84 |
enum enum_drizzle_timestamp_type |
85 |
str_to_datetime(const char *str, uint length, DRIZZLE_TIME *l_time, |
|
1
by brian
clean slate |
86 |
uint flags, int *was_cut); |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
87 |
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res, |
1
by brian
clean slate |
88 |
uint flags, int *was_cut); |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
89 |
uint64_t TIME_to_uint64_t_datetime(const DRIZZLE_TIME *); |
90 |
uint64_t TIME_to_uint64_t_date(const DRIZZLE_TIME *); |
|
91 |
uint64_t TIME_to_uint64_t_time(const DRIZZLE_TIME *); |
|
92 |
uint64_t TIME_to_uint64_t(const DRIZZLE_TIME *); |
|
93 |
||
94 |
||
236.1.26
by Monty Taylor
my_bool cleanup in libdrizzle time stuff. |
95 |
bool str_to_time(const char *str,uint length, DRIZZLE_TIME *l_time, |
96 |
int *warning); |
|
1
by brian
clean slate |
97 |
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
98 |
int check_time_range(DRIZZLE_TIME *my_time, int *warning); |
1
by brian
clean slate |
99 |
|
100 |
long calc_daynr(uint year,uint month,uint day); |
|
101 |
uint calc_days_in_year(uint year); |
|
102 |
uint year_2000_handling(uint year); |
|
103 |
||
104 |
void init_time(void); |
|
105 |
||
106 |
||
107 |
/*
|
|
108 |
Function to check sanity of a TIMESTAMP value
|
|
109 |
||
110 |
DESCRIPTION
|
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
111 |
Check if a given DRIZZLE_TIME value fits in TIMESTAMP range.
|
1
by brian
clean slate |
112 |
This function doesn't make precise check, but rather a rough
|
113 |
estimate.
|
|
114 |
||
115 |
RETURN VALUES
|
|
163
by Brian Aker
Merge Monty's code. |
116 |
false The value seems sane
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
117 |
true The DRIZZLE_TIME value is definitely out of range
|
1
by brian
clean slate |
118 |
*/
|
119 |
||
236.1.26
by Monty Taylor
my_bool cleanup in libdrizzle time stuff. |
120 |
static inline bool validate_timestamp_range(const DRIZZLE_TIME *t) |
1
by brian
clean slate |
121 |
{
|
122 |
if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) || |
|
123 |
(t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) || |
|
124 |
(t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31))) |
|
163
by Brian Aker
Merge Monty's code. |
125 |
return false; |
1
by brian
clean slate |
126 |
|
163
by Brian Aker
Merge Monty's code. |
127 |
return true; |
1
by brian
clean slate |
128 |
}
|
129 |
||
130 |
my_time_t
|
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
131 |
my_system_gmt_sec(const DRIZZLE_TIME *t, long *my_timezone, |
93
by Brian Aker
Convert tztime.cc to bool from my_bool. |
132 |
bool *in_dst_time_gap); |
1
by brian
clean slate |
133 |
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
134 |
void set_zero_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type time_type); |
1
by brian
clean slate |
135 |
|
136 |
/*
|
|
137 |
Required buffer length for my_time_to_str, my_date_to_str,
|
|
138 |
my_datetime_to_str and TIME_to_string functions. Note, that the
|
|
139 |
caller is still responsible to check that given TIME structure
|
|
140 |
has values in valid ranges, otherwise size of the buffer could
|
|
141 |
be not enough. We also rely on the fact that even wrong values
|
|
142 |
sent using binary protocol fit in this buffer.
|
|
143 |
*/
|
|
144 |
#define MAX_DATE_STRING_REP_LENGTH 30
|
|
145 |
||
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
146 |
int my_time_to_str(const DRIZZLE_TIME *l_time, char *to); |
147 |
int my_date_to_str(const DRIZZLE_TIME *l_time, char *to); |
|
148 |
int my_datetime_to_str(const DRIZZLE_TIME *l_time, char *to); |
|
149 |
int my_TIME_to_str(const DRIZZLE_TIME *l_time, char *to); |
|
1
by brian
clean slate |
150 |
|
151 |
/*
|
|
152 |
Available interval types used in any statement.
|
|
153 |
||
154 |
'interval_type' must be sorted so that simple intervals comes first,
|
|
155 |
ie year, quarter, month, week, day, hour, etc. The order based on
|
|
156 |
interval size is also important and the intervals should be kept in a
|
|
157 |
large to smaller order. (get_interval_value() depends on this)
|
|
158 |
|
|
159 |
Note: If you change the order of elements in this enum you should fix
|
|
160 |
order of elements in 'interval_type_to_name' and 'interval_names'
|
|
161 |
arrays
|
|
162 |
|
|
163 |
See also interval_type_to_name, get_interval_value, interval_names
|
|
164 |
*/
|
|
165 |
||
166 |
enum interval_type |
|
167 |
{
|
|
168 |
INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_WEEK, INTERVAL_DAY, |
|
169 |
INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND, INTERVAL_MICROSECOND, |
|
170 |
INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE, |
|
171 |
INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND, |
|
172 |
INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND, |
|
173 |
INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND, INTERVAL_LAST |
|
174 |
};
|
|
175 |
||
176 |
C_MODE_END
|
|
177 |
||
236.1.23
by Monty Taylor
Cleaned header headers. |
178 |
#endif /* _libdrizzle_my_time_h_ */ |