~drizzle-trunk/drizzle/development

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
1122.2.10 by Monty Taylor
Fixed all of the include guards.
26
#ifndef MYSYS_MY_TIME_H
27
#define MYSYS_MY_TIME_H
236.1.23 by Monty Taylor
Cleaned header headers.
28
77.1.39 by Monty Taylor
More mysql->drizzle renaming.
29
#include "drizzle_time.h"
1 by brian
clean slate
30
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
31
#ifdef __cplusplus
32
extern "C" {
33
#endif
1 by brian
clean slate
34
151 by Brian Aker
Ulonglong to uint64_t
35
extern uint64_t log_10_int[20];
481 by Brian Aker
Remove all of uchar.
36
extern unsigned char days_in_month[];
1 by brian
clean slate
37
38
/* Time handling defaults */
39
#define TIMESTAMP_MAX_YEAR 2038
40
#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
163 by Brian Aker
Merge Monty's code.
41
#define TIMESTAMP_MAX_VALUE INT32_MAX
1 by brian
clean slate
42
#define TIMESTAMP_MIN_VALUE 1
43
44
/* two-digit years < this are 20..; >= this are 19.. */
45
#define YY_PART_YEAR	   70
46
47
/* Flags to str_to_datetime */
48
#define TIME_FUZZY_DATE		1
49
#define TIME_DATETIME_ONLY	2
50
/* Must be same as MODE_NO_ZERO_IN_DATE */
51
#define TIME_NO_ZERO_IN_DATE    (65536L*2*2*2*2*2*2*2)
52
/* Must be same as MODE_NO_ZERO_DATE */
53
#define TIME_NO_ZERO_DATE	(TIME_NO_ZERO_IN_DATE*2)
54
#define TIME_INVALID_DATES	(TIME_NO_ZERO_DATE*2)
55
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
56
#define DRIZZLE_TIME_WARN_TRUNCATED    1
57
#define DRIZZLE_TIME_WARN_OUT_OF_RANGE 2
1 by brian
clean slate
58
59
/* Limits for the TIME data type */
60
#define TIME_MAX_HOUR 838
61
#define TIME_MAX_MINUTE 59
62
#define TIME_MAX_SECOND 59
63
#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \
64
                        TIME_MAX_SECOND)
65
#define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \
66
                                TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
67
236.1.26 by Monty Taylor
my_bool cleanup in libdrizzle time stuff.
68
bool check_date(const DRIZZLE_TIME *ltime, bool not_zero_date,
294 by Brian Aker
libdrizzle has ulong removed.
69
                   uint32_t flags, int *was_cut);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
70
enum enum_drizzle_timestamp_type
482 by Brian Aker
Remove uint.
71
str_to_datetime(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
72
                uint32_t flags, int *was_cut);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
73
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res,
482 by Brian Aker
Remove uint.
74
                            uint32_t flags, int *was_cut);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
75
uint64_t TIME_to_uint64_t_datetime(const DRIZZLE_TIME *);
76
uint64_t TIME_to_uint64_t(const DRIZZLE_TIME *);
77
78
482 by Brian Aker
Remove uint.
79
bool str_to_time(const char *str,uint32_t length, DRIZZLE_TIME *l_time,
236.1.26 by Monty Taylor
my_bool cleanup in libdrizzle time stuff.
80
                 int *warning);
1 by brian
clean slate
81
482 by Brian Aker
Remove uint.
82
long calc_daynr(uint32_t year,uint32_t month,uint32_t day);
83
uint32_t calc_days_in_year(uint32_t year);
84
uint32_t year_2000_handling(uint32_t year);
1 by brian
clean slate
85
86
void init_time(void);
87
88
89
/*
90
  Function to check sanity of a TIMESTAMP value
91
92
  DESCRIPTION
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
93
    Check if a given DRIZZLE_TIME value fits in TIMESTAMP range.
1 by brian
clean slate
94
    This function doesn't make precise check, but rather a rough
95
    estimate.
96
97
  RETURN VALUES
163 by Brian Aker
Merge Monty's code.
98
    false   The value seems sane
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
99
    true    The DRIZZLE_TIME value is definitely out of range
1 by brian
clean slate
100
*/
101
236.1.26 by Monty Taylor
my_bool cleanup in libdrizzle time stuff.
102
static inline bool validate_timestamp_range(const DRIZZLE_TIME *t)
1 by brian
clean slate
103
{
104
  if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
105
      (t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
106
      (t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31)))
163 by Brian Aker
Merge Monty's code.
107
    return false;
1 by brian
clean slate
108
163 by Brian Aker
Merge Monty's code.
109
  return true;
1 by brian
clean slate
110
}
111
722.1.8 by Monty Taylor
Merged from Toru - removal of my_time_t.
112
time_t
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
113
my_system_gmt_sec(const DRIZZLE_TIME *t, long *my_timezone,
93 by Brian Aker
Convert tztime.cc to bool from my_bool.
114
                  bool *in_dst_time_gap);
1 by brian
clean slate
115
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
116
void set_zero_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type time_type);
1 by brian
clean slate
117
118
/*
119
  Required buffer length for my_time_to_str, my_date_to_str,
120
  my_datetime_to_str and TIME_to_string functions. Note, that the
121
  caller is still responsible to check that given TIME structure
122
  has values in valid ranges, otherwise size of the buffer could
123
  be not enough. We also rely on the fact that even wrong values
124
  sent using binary protocol fit in this buffer.
125
*/
126
#define MAX_DATE_STRING_REP_LENGTH 30
127
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
128
int my_date_to_str(const DRIZZLE_TIME *l_time, char *to);
129
int my_datetime_to_str(const DRIZZLE_TIME *l_time, char *to);
130
int my_TIME_to_str(const DRIZZLE_TIME *l_time, char *to);
1 by brian
clean slate
131
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
132
/*
1 by brian
clean slate
133
  Available interval types used in any statement.
134
135
  'interval_type' must be sorted so that simple intervals comes first,
136
  ie year, quarter, month, week, day, hour, etc. The order based on
137
  interval size is also important and the intervals should be kept in a
138
  large to smaller order. (get_interval_value() depends on this)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
139
140
  Note: If you change the order of elements in this enum you should fix
141
  order of elements in 'interval_type_to_name' and 'interval_names'
142
  arrays
143
1 by brian
clean slate
144
  See also interval_type_to_name, get_interval_value, interval_names
145
*/
146
147
enum interval_type
148
{
149
  INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_WEEK, INTERVAL_DAY,
150
  INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND, INTERVAL_MICROSECOND,
151
  INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE,
152
  INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND,
153
  INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND,
154
  INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND, INTERVAL_LAST
155
};
156
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
157
#ifdef __cplusplus
158
}
159
#endif
1 by brian
clean slate
160
1122.2.10 by Monty Taylor
Fixed all of the include guards.
161
#endif /* MYSYS_MY_TIME_H */