~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
1241.9.53 by Monty Taylor
Drizzle_time is part of the API.
21
#ifndef DRIZZLED_MY_TIME_H
22
#define DRIZZLED_MY_TIME_H
236.1.23 by Monty Taylor
Cleaned header headers.
23
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
24
#if TIME_WITH_SYS_TIME
25
# include <sys/time.h>
26
# include <time.h>
27
#else
28
# if HAVE_SYS_TIME_H
29
#  include <sys/time.h>
30
# else
31
#  include <time.h>
32
# endif
33
#endif
34
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
35
namespace drizzled
36
{
1 by brian
clean slate
37
151 by Brian Aker
Ulonglong to uint64_t
38
extern uint64_t log_10_int[20];
481 by Brian Aker
Remove all of uchar.
39
extern unsigned char days_in_month[];
1 by brian
clean slate
40
41
/* Time handling defaults */
42
#define TIMESTAMP_MAX_YEAR 2038
43
#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
163 by Brian Aker
Merge Monty's code.
44
#define TIMESTAMP_MAX_VALUE INT32_MAX
1 by brian
clean slate
45
#define TIMESTAMP_MIN_VALUE 1
46
47
/* two-digit years < this are 20..; >= this are 19.. */
48
#define YY_PART_YEAR	   70
49
50
/* Flags to str_to_datetime */
51
#define TIME_FUZZY_DATE		1
52
#define TIME_DATETIME_ONLY	2
53
/* Must be same as MODE_NO_ZERO_IN_DATE */
54
#define TIME_NO_ZERO_IN_DATE    (65536L*2*2*2*2*2*2*2)
55
/* Must be same as MODE_NO_ZERO_DATE */
56
#define TIME_NO_ZERO_DATE	(TIME_NO_ZERO_IN_DATE*2)
57
#define TIME_INVALID_DATES	(TIME_NO_ZERO_DATE*2)
58
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
59
#define DRIZZLE_TIME_WARN_TRUNCATED    1
60
#define DRIZZLE_TIME_WARN_OUT_OF_RANGE 2
1 by brian
clean slate
61
62
/* Limits for the TIME data type */
63
#define TIME_MAX_HOUR 838
64
#define TIME_MAX_MINUTE 59
65
#define TIME_MAX_SECOND 59
66
#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \
67
                        TIME_MAX_SECOND)
68
#define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \
69
                                TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
70
1241.9.53 by Monty Taylor
Drizzle_time is part of the API.
71
enum enum_drizzle_timestamp_type
72
{
73
  DRIZZLE_TIMESTAMP_NONE= -2, DRIZZLE_TIMESTAMP_ERROR= -1,
74
  DRIZZLE_TIMESTAMP_DATE= 0, DRIZZLE_TIMESTAMP_DATETIME= 1, DRIZZLE_TIMESTAMP_TIME= 2
75
};
76
77
78
/*
79
  Structure which is used to represent datetime values inside Drizzle.
80
81
  We assume that values in this structure are normalized, i.e. year <= 9999,
82
  month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions
83
  in server such as my_system_gmt_sec() or make_time() family of functions
84
  rely on this (actually now usage of make_*() family relies on a bit weaker
85
  restriction). Also functions that produce DRIZZLE_TIME as result ensure this.
86
  There is one exception to this rule though if this structure holds time
87
  value (time_type == DRIZZLE_TIMESTAMP_TIME) days and hour member can hold
88
  bigger values.
89
*/
90
typedef struct st_drizzle_time
91
{
92
  unsigned int  year, month, day, hour, minute, second;
93
  unsigned long second_part;
94
  bool       neg;
95
  enum enum_drizzle_timestamp_type time_type;
96
} DRIZZLE_TIME;
97
98
236.1.26 by Monty Taylor
my_bool cleanup in libdrizzle time stuff.
99
bool check_date(const DRIZZLE_TIME *ltime, bool not_zero_date,
294 by Brian Aker
libdrizzle has ulong removed.
100
                   uint32_t flags, int *was_cut);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
101
enum enum_drizzle_timestamp_type
482 by Brian Aker
Remove uint.
102
str_to_datetime(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
103
                uint32_t flags, int *was_cut);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
104
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res,
482 by Brian Aker
Remove uint.
105
                            uint32_t flags, int *was_cut);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
106
uint64_t TIME_to_uint64_t_datetime(const DRIZZLE_TIME *);
107
uint64_t TIME_to_uint64_t(const DRIZZLE_TIME *);
108
109
482 by Brian Aker
Remove uint.
110
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.
111
                 int *warning);
1 by brian
clean slate
112
482 by Brian Aker
Remove uint.
113
long calc_daynr(uint32_t year,uint32_t month,uint32_t day);
114
uint32_t calc_days_in_year(uint32_t year);
115
uint32_t year_2000_handling(uint32_t year);
1 by brian
clean slate
116
117
void init_time(void);
118
119
120
/*
121
  Function to check sanity of a TIMESTAMP value
122
123
  DESCRIPTION
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
124
    Check if a given DRIZZLE_TIME value fits in TIMESTAMP range.
1 by brian
clean slate
125
    This function doesn't make precise check, but rather a rough
126
    estimate.
127
128
  RETURN VALUES
163 by Brian Aker
Merge Monty's code.
129
    false   The value seems sane
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
130
    true    The DRIZZLE_TIME value is definitely out of range
1 by brian
clean slate
131
*/
132
236.1.26 by Monty Taylor
my_bool cleanup in libdrizzle time stuff.
133
static inline bool validate_timestamp_range(const DRIZZLE_TIME *t)
1 by brian
clean slate
134
{
135
  if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
136
      (t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
137
      (t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31)))
163 by Brian Aker
Merge Monty's code.
138
    return false;
1 by brian
clean slate
139
163 by Brian Aker
Merge Monty's code.
140
  return true;
1 by brian
clean slate
141
}
142
722.1.8 by Monty Taylor
Merged from Toru - removal of my_time_t.
143
time_t
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
144
my_system_gmt_sec(const DRIZZLE_TIME *t, long *my_timezone,
93 by Brian Aker
Convert tztime.cc to bool from my_bool.
145
                  bool *in_dst_time_gap);
1 by brian
clean slate
146
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
147
void set_zero_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type time_type);
1 by brian
clean slate
148
149
/*
150
  Required buffer length for my_time_to_str, my_date_to_str,
151
  my_datetime_to_str and TIME_to_string functions. Note, that the
152
  caller is still responsible to check that given TIME structure
153
  has values in valid ranges, otherwise size of the buffer could
154
  be not enough. We also rely on the fact that even wrong values
155
  sent using binary protocol fit in this buffer.
156
*/
157
#define MAX_DATE_STRING_REP_LENGTH 30
158
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
159
int my_date_to_str(const DRIZZLE_TIME *l_time, char *to);
160
int my_datetime_to_str(const DRIZZLE_TIME *l_time, char *to);
161
int my_TIME_to_str(const DRIZZLE_TIME *l_time, char *to);
1 by brian
clean slate
162
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
163
/*
1 by brian
clean slate
164
  Available interval types used in any statement.
165
166
  'interval_type' must be sorted so that simple intervals comes first,
167
  ie year, quarter, month, week, day, hour, etc. The order based on
168
  interval size is also important and the intervals should be kept in a
169
  large to smaller order. (get_interval_value() depends on this)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
170
171
  Note: If you change the order of elements in this enum you should fix
172
  order of elements in 'interval_type_to_name' and 'interval_names'
173
  arrays
174
1 by brian
clean slate
175
  See also interval_type_to_name, get_interval_value, interval_names
176
*/
177
178
enum interval_type
179
{
180
  INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_WEEK, INTERVAL_DAY,
181
  INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND, INTERVAL_MICROSECOND,
182
  INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE,
183
  INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND,
184
  INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND,
185
  INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND, INTERVAL_LAST
186
};
187
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
188
extern uint64_t my_getsystime(void);
189
extern uint64_t my_micro_time(void);
190
extern uint64_t my_micro_time_and_time(time_t *time_arg);
191
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
192
} /* namespace drizzled */
1 by brian
clean slate
193
1241.9.53 by Monty Taylor
Drizzle_time is part of the API.
194
#endif /* DRIZZLED_MY_TIME_H */