~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to include/my_time.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

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