76
82
month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions
77
83
in server such as my_system_gmt_sec() or make_time() family of functions
78
84
rely on this (actually now usage of make_*() family relies on a bit weaker
79
restriction). Also functions that produce type::Time as result ensure this.
85
restriction). Also functions that produce DRIZZLE_TIME as result ensure this.
80
86
There is one exception to this rule though if this structure holds time
81
87
value (time_type == DRIZZLE_TIMESTAMP_TIME) days and hour member can hold
88
DRIZZLE_TIMESTAMP_NONE= -2, DRIZZLE_TIMESTAMP_ERROR= -1,
89
DRIZZLE_TIMESTAMP_DATE= 0, DRIZZLE_TIMESTAMP_DATETIME= 1, DRIZZLE_TIMESTAMP_TIME= 2
100
datatime_t while being stored in an integer is actually a formatted value.
102
typedef int64_t datetime_t;
103
typedef int64_t date_t;
105
inline bool is_valid(const datetime_t &value)
116
typedef uint32_t usec_t;
117
typedef int64_t epoch_t;
124
Time(uint32_t year_arg,
130
usec_t second_part_arg,
131
timestamp_t type_arg) :
138
second_part(second_part_arg),
141
_is_local_time(false)
145
Time(uint32_t hour_arg,
148
usec_t second_part_arg,
156
second_part(second_part_arg),
158
time_type(DRIZZLE_TIMESTAMP_TIME),
159
_is_local_time(false)
163
uint32_t year, month, day, hour, minute, second;
166
timestamp_t time_type;
171
year= month= day= hour= minute= second= second_part= 0;
173
time_type= DRIZZLE_TIMESTAMP_DATE;
174
_is_local_time= false;
177
timestamp_t type() const
182
void convert(drizzled::String &str, timestamp_t arg= type::DRIZZLE_TIMESTAMP_DATETIME);
183
void convert(char *str, size_t &to_length, timestamp_t arg= type::DRIZZLE_TIMESTAMP_DATETIME);
184
void convert(datetime_t &datetime, timestamp_t arg= type::DRIZZLE_TIMESTAMP_DATETIME);
185
void convert(datetime_t &ret, int64_t nr, uint32_t flags);
186
void convert(datetime_t &ret, int64_t nr, uint32_t flags, type::cut_t &was_cut);
187
void convert(type::Time::epoch_t &epoch, long *my_timezone,
188
bool *in_dst_time_gap, bool skip_timezone= false) const;
190
void truncate(const timestamp_t arg);
192
bool store(const char *str,uint32_t length, int &warning, type::timestamp_t arg= DRIZZLE_TIMESTAMP_TIME);
193
type::timestamp_t store(const char *str, uint32_t length, uint32_t flags, type::cut_t &was_cut);
194
type::timestamp_t store(const char *str, uint32_t length, uint32_t flags);
195
void store(const type::Time::epoch_t &from, bool use_localtime= false);
196
void store(const type::Time::epoch_t &from, const usec_t &from_fractional_seconds, bool use_localtime= false);
197
void store(const struct tm &from);
198
void store(const struct timeval &from);
201
static const uint32_t FRACTIONAL_DIGITS= 1000000;
202
static const size_t MAX_STRING_LENGTH= 32; // +32 to make my_snprintf_{8bit|ucs2} happy
204
bool check(bool not_zero_date, uint32_t flags, type::cut_t &was_cut) const;
206
inline bool isValidEpoch() const
208
if ((year < TIMESTAMP_MIN_YEAR) or (year == TIMESTAMP_MIN_YEAR && (month < 12 || day < 31)))
90
typedef struct st_drizzle_time
92
unsigned int year, month, day, hour, minute, second;
93
unsigned long second_part;
95
enum enum_drizzle_timestamp_type time_type;
99
bool check_date(const DRIZZLE_TIME *ltime, bool not_zero_date,
100
uint32_t flags, int *was_cut);
101
enum enum_drizzle_timestamp_type
102
str_to_datetime(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
103
uint32_t flags, int *was_cut);
104
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res,
105
uint32_t flags, int *was_cut);
106
uint64_t TIME_to_uint64_t_datetime(const DRIZZLE_TIME *);
107
uint64_t TIME_to_uint64_t(const DRIZZLE_TIME *);
110
bool str_to_time(const char *str,uint32_t length, DRIZZLE_TIME *l_time,
219
113
long calc_daynr(uint32_t year,uint32_t month,uint32_t day);
220
114
uint32_t calc_days_in_year(uint32_t year);
223
117
void init_time(void);
121
Function to check sanity of a TIMESTAMP value
124
Check if a given DRIZZLE_TIME value fits in TIMESTAMP range.
125
This function doesn't make precise check, but rather a rough
129
false The value seems sane
130
true The DRIZZLE_TIME value is definitely out of range
133
static inline bool validate_timestamp_range(const DRIZZLE_TIME *t)
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)))
144
my_system_gmt_sec(const DRIZZLE_TIME *t, long *my_timezone,
145
bool *in_dst_time_gap);
147
void set_zero_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type time_type);
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.
157
#define MAX_DATE_STRING_REP_LENGTH 30
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);
226
164
Available interval types used in any statement.