1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
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.
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.
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
22
This is a private header of sql-common library, containing
23
declarations for my_time.c
26
#ifndef _libdrizzle_my_time_h_
27
#define _libdrizzle_my_time_h_
29
#include <drizzled/global.h>
30
#include "drizzle_time.h"
36
extern uint64_t log_10_int[20];
37
extern unsigned char days_in_month[];
39
/* Time handling defaults */
40
#define TIMESTAMP_MAX_YEAR 2038
41
#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
42
#define TIMESTAMP_MAX_VALUE INT32_MAX
43
#define TIMESTAMP_MIN_VALUE 1
45
/* two-digit years < this are 20..; >= this are 19.. */
46
#define YY_PART_YEAR 70
48
/* Flags to str_to_datetime */
49
#define TIME_FUZZY_DATE 1
50
#define TIME_DATETIME_ONLY 2
51
/* Must be same as MODE_NO_ZERO_IN_DATE */
52
#define TIME_NO_ZERO_IN_DATE (65536L*2*2*2*2*2*2*2)
53
/* Must be same as MODE_NO_ZERO_DATE */
54
#define TIME_NO_ZERO_DATE (TIME_NO_ZERO_IN_DATE*2)
55
#define TIME_INVALID_DATES (TIME_NO_ZERO_DATE*2)
57
#define DRIZZLE_TIME_WARN_TRUNCATED 1
58
#define DRIZZLE_TIME_WARN_OUT_OF_RANGE 2
60
/* Limits for the TIME data type */
61
#define TIME_MAX_HOUR 838
62
#define TIME_MAX_MINUTE 59
63
#define TIME_MAX_SECOND 59
64
#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \
66
#define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \
67
TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
69
bool check_date(const DRIZZLE_TIME *ltime, bool not_zero_date,
70
uint32_t flags, int *was_cut);
71
enum enum_drizzle_timestamp_type
72
str_to_datetime(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
73
uint32_t flags, int *was_cut);
74
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res,
75
uint32_t flags, int *was_cut);
76
uint64_t TIME_to_uint64_t_datetime(const DRIZZLE_TIME *);
77
uint64_t TIME_to_uint64_t_date(const DRIZZLE_TIME *);
78
uint64_t TIME_to_uint64_t_time(const DRIZZLE_TIME *);
79
uint64_t TIME_to_uint64_t(const DRIZZLE_TIME *);
82
bool str_to_time(const char *str,uint32_t length, DRIZZLE_TIME *l_time,
85
int check_time_range(DRIZZLE_TIME *my_time, int *warning);
87
long calc_daynr(uint32_t year,uint32_t month,uint32_t day);
88
uint32_t calc_days_in_year(uint32_t year);
89
uint32_t year_2000_handling(uint32_t year);
95
Function to check sanity of a TIMESTAMP value
98
Check if a given DRIZZLE_TIME value fits in TIMESTAMP range.
99
This function doesn't make precise check, but rather a rough
103
false The value seems sane
104
true The DRIZZLE_TIME value is definitely out of range
107
static inline bool validate_timestamp_range(const DRIZZLE_TIME *t)
109
if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
110
(t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
111
(t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31)))
118
my_system_gmt_sec(const DRIZZLE_TIME *t, long *my_timezone,
119
bool *in_dst_time_gap);
121
void set_zero_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type time_type);
124
Required buffer length for my_time_to_str, my_date_to_str,
125
my_datetime_to_str and TIME_to_string functions. Note, that the
126
caller is still responsible to check that given TIME structure
127
has values in valid ranges, otherwise size of the buffer could
128
be not enough. We also rely on the fact that even wrong values
129
sent using binary protocol fit in this buffer.
131
#define MAX_DATE_STRING_REP_LENGTH 30
133
int my_time_to_str(const DRIZZLE_TIME *l_time, char *to);
134
int my_date_to_str(const DRIZZLE_TIME *l_time, char *to);
135
int my_datetime_to_str(const DRIZZLE_TIME *l_time, char *to);
136
int my_TIME_to_str(const DRIZZLE_TIME *l_time, char *to);
139
Available interval types used in any statement.
141
'interval_type' must be sorted so that simple intervals comes first,
142
ie year, quarter, month, week, day, hour, etc. The order based on
143
interval size is also important and the intervals should be kept in a
144
large to smaller order. (get_interval_value() depends on this)
146
Note: If you change the order of elements in this enum you should fix
147
order of elements in 'interval_type_to_name' and 'interval_names'
150
See also interval_type_to_name, get_interval_value, interval_names
155
INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_WEEK, INTERVAL_DAY,
156
INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND, INTERVAL_MICROSECOND,
157
INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE,
158
INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND,
159
INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND,
160
INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND, INTERVAL_LAST
167
#endif /* _libdrizzle_my_time_h_ */