78
82
month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions
79
83
in server such as my_system_gmt_sec() or make_time() family of functions
80
84
rely on this (actually now usage of make_*() family relies on a bit weaker
81
restriction). Also functions that produce type::Time as result ensure this.
85
restriction). Also functions that produce DRIZZLE_TIME as result ensure this.
82
86
There is one exception to this rule though if this structure holds time
83
87
value (time_type == DRIZZLE_TIMESTAMP_TIME) days and hour member can hold
90
DRIZZLE_TIMESTAMP_NONE= -2, DRIZZLE_TIMESTAMP_ERROR= -1,
91
DRIZZLE_TIMESTAMP_DATE= 0, DRIZZLE_TIMESTAMP_DATETIME= 1, DRIZZLE_TIMESTAMP_TIME= 2
102
datatime_t while being stored in an integer is actually a formatted value.
104
typedef int64_t datetime_t;
105
typedef int64_t date_t;
107
inline bool is_valid(const datetime_t &value)
118
typedef uint32_t usec_t;
119
typedef int64_t epoch_t;
126
Time(uint32_t year_arg,
132
usec_t second_part_arg,
133
timestamp_t type_arg) :
140
second_part(second_part_arg),
143
_is_local_time(false)
147
Time(uint32_t hour_arg,
150
usec_t second_part_arg,
158
second_part(second_part_arg),
160
time_type(DRIZZLE_TIMESTAMP_TIME),
161
_is_local_time(false)
165
uint32_t year, month, day, hour, minute, second;
168
timestamp_t time_type;
173
year= month= day= hour= minute= second= second_part= 0;
175
time_type= DRIZZLE_TIMESTAMP_DATE;
176
_is_local_time= false;
179
timestamp_t type() const
184
void convert(drizzled::String &str, timestamp_t arg= type::DRIZZLE_TIMESTAMP_DATETIME);
185
void convert(char *str, size_t &to_length, timestamp_t arg= type::DRIZZLE_TIMESTAMP_DATETIME);
186
void convert(datetime_t &datetime, timestamp_t arg= type::DRIZZLE_TIMESTAMP_DATETIME);
187
void convert(datetime_t &ret, int64_t nr, uint32_t flags);
188
void convert(datetime_t &ret, int64_t nr, uint32_t flags, type::cut_t &was_cut);
189
void convert(type::Time::epoch_t &epoch, long *my_timezone,
190
bool *in_dst_time_gap, bool skip_timezone= false) const;
192
void truncate(const timestamp_t arg);
194
bool store(const char *str,uint32_t length, int &warning, type::timestamp_t arg= DRIZZLE_TIMESTAMP_TIME);
195
type::timestamp_t store(const char *str, uint32_t length, uint32_t flags, type::cut_t &was_cut);
196
type::timestamp_t store(const char *str, uint32_t length, uint32_t flags);
197
void store(const type::Time::epoch_t &from, bool use_localtime= false);
198
void store(const type::Time::epoch_t &from, const usec_t &from_fractional_seconds, bool use_localtime= false);
199
void store(const struct tm &from);
200
void store(const struct timeval &from);
203
static const uint32_t FRACTIONAL_DIGITS= 1000000;
204
static const size_t MAX_STRING_LENGTH= 32; // +32 to make my_snprintf_{8bit|ucs2} happy
206
bool check(bool not_zero_date, uint32_t flags, type::cut_t &was_cut) const;
208
inline bool isValidEpoch() const
210
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,
221
113
long calc_daynr(uint32_t year,uint32_t month,uint32_t day);
222
114
uint32_t calc_days_in_year(uint32_t year);
225
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);
228
164
Available interval types used in any statement.