~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/my_time.h

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
/* Copyright (C) 2004-2005 MySQL AB
 
2
 
 
3
 This program is free software; you can redistribute it and/or modify
 
4
 it under the terms of the GNU General Public License as published by
 
5
 the Free Software Foundation; version 2 of the License.
 
6
 
 
7
 This program is distributed in the hope that it will be useful,
 
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 GNU General Public License for more details.
 
11
 
 
12
 You should have received a copy of the GNU General Public License
 
13
 along with this program; if not, write to the Free Software
 
14
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
20
15
 
21
16
/*
22
17
  This is a private header of sql-common library, containing
23
18
  declarations for my_time.c
24
19
*/
25
20
 
26
 
#ifndef _libdrizzle_my_time_h_
27
 
#define _libdrizzle_my_time_h_
28
 
 
29
 
#include <drizzled/global.h>
30
 
#include "drizzle_time.h"
31
 
 
32
 
#ifdef __cplusplus
33
 
extern "C" {
34
 
#endif
35
 
 
36
 
extern uint64_t log_10_int[20];
37
 
extern unsigned char days_in_month[];
 
21
#ifndef _my_time_h_
 
22
#define _my_time_h_
 
23
#include "my_global.h"
 
24
#include "mysql_time.h"
 
25
 
 
26
C_MODE_START
 
27
 
 
28
extern ulonglong log_10_int[20];
 
29
extern uchar days_in_month[];
38
30
 
39
31
/*
40
32
  Portable time_t replacement.
48
40
*/
49
41
typedef long my_time_t;
50
42
 
51
 
#define MY_TIME_T_MAX INT32_MAX
52
 
#define MY_TIME_T_MIN INT32_MIN
 
43
#define MY_TIME_T_MAX LONG_MAX
 
44
#define MY_TIME_T_MIN LONG_MIN
53
45
 
54
46
/* Time handling defaults */
55
47
#define TIMESTAMP_MAX_YEAR 2038
56
48
#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
57
 
#define TIMESTAMP_MAX_VALUE INT32_MAX
 
49
#define TIMESTAMP_MAX_VALUE INT_MAX32
58
50
#define TIMESTAMP_MIN_VALUE 1
59
51
 
60
52
/* two-digit years < this are 20..; >= this are 19.. */
69
61
#define TIME_NO_ZERO_DATE       (TIME_NO_ZERO_IN_DATE*2)
70
62
#define TIME_INVALID_DATES      (TIME_NO_ZERO_DATE*2)
71
63
 
72
 
#define DRIZZLE_TIME_WARN_TRUNCATED    1
73
 
#define DRIZZLE_TIME_WARN_OUT_OF_RANGE 2
 
64
#define MYSQL_TIME_WARN_TRUNCATED    1
 
65
#define MYSQL_TIME_WARN_OUT_OF_RANGE 2
74
66
 
75
67
/* Limits for the TIME data type */
76
68
#define TIME_MAX_HOUR 838
81
73
#define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \
82
74
                                TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
83
75
 
84
 
bool check_date(const DRIZZLE_TIME *ltime, bool not_zero_date,
85
 
                   uint32_t flags, int *was_cut);
86
 
enum enum_drizzle_timestamp_type
87
 
str_to_datetime(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
88
 
                uint32_t flags, int *was_cut);
89
 
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res,
90
 
                            uint32_t flags, int *was_cut);
91
 
uint64_t TIME_to_uint64_t_datetime(const DRIZZLE_TIME *);
92
 
uint64_t TIME_to_uint64_t_date(const DRIZZLE_TIME *);
93
 
uint64_t TIME_to_uint64_t_time(const DRIZZLE_TIME *);
94
 
uint64_t TIME_to_uint64_t(const DRIZZLE_TIME *);
95
 
 
96
 
 
97
 
bool str_to_time(const char *str,uint32_t length, DRIZZLE_TIME *l_time,
98
 
                 int *warning);
99
 
 
100
 
int check_time_range(DRIZZLE_TIME *my_time, int *warning);
101
 
 
102
 
long calc_daynr(uint32_t year,uint32_t month,uint32_t day);
103
 
uint32_t calc_days_in_year(uint32_t year);
104
 
uint32_t year_2000_handling(uint32_t year);
 
76
my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date,
 
77
                   ulong flags, int *was_cut);
 
78
enum enum_mysql_timestamp_type
 
79
str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
 
80
                uint flags, int *was_cut);
 
81
longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
 
82
                            uint flags, int *was_cut);
 
83
ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *);
 
84
ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *);
 
85
ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *);
 
86
ulonglong TIME_to_ulonglong(const MYSQL_TIME *);
 
87
 
 
88
 
 
89
my_bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time,
 
90
                    int *warning);
 
91
 
 
92
int check_time_range(struct st_mysql_time *, int *warning);
 
93
 
 
94
long calc_daynr(uint year,uint month,uint day);
 
95
uint calc_days_in_year(uint year);
 
96
uint year_2000_handling(uint year);
105
97
 
106
98
void init_time(void);
107
99
 
110
102
  Function to check sanity of a TIMESTAMP value
111
103
 
112
104
  DESCRIPTION
113
 
    Check if a given DRIZZLE_TIME value fits in TIMESTAMP range.
 
105
    Check if a given MYSQL_TIME value fits in TIMESTAMP range.
114
106
    This function doesn't make precise check, but rather a rough
115
107
    estimate.
116
108
 
117
109
  RETURN VALUES
118
 
    false   The value seems sane
119
 
    true    The DRIZZLE_TIME value is definitely out of range
 
110
    FALSE   The value seems sane
 
111
    TRUE    The MYSQL_TIME value is definitely out of range
120
112
*/
121
113
 
122
 
static inline bool validate_timestamp_range(const DRIZZLE_TIME *t)
 
114
static inline my_bool validate_timestamp_range(const MYSQL_TIME *t)
123
115
{
124
116
  if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
125
117
      (t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
126
118
      (t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31)))
127
 
    return false;
 
119
    return FALSE;
128
120
 
129
 
  return true;
 
121
  return TRUE;
130
122
}
131
123
 
132
124
my_time_t 
133
 
my_system_gmt_sec(const DRIZZLE_TIME *t, long *my_timezone,
134
 
                  bool *in_dst_time_gap);
 
125
my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone,
 
126
                  my_bool *in_dst_time_gap);
135
127
 
136
 
void set_zero_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type time_type);
 
128
void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type);
137
129
 
138
130
/*
139
131
  Required buffer length for my_time_to_str, my_date_to_str,
145
137
*/
146
138
#define MAX_DATE_STRING_REP_LENGTH 30
147
139
 
148
 
int my_time_to_str(const DRIZZLE_TIME *l_time, char *to);
149
 
int my_date_to_str(const DRIZZLE_TIME *l_time, char *to);
150
 
int my_datetime_to_str(const DRIZZLE_TIME *l_time, char *to);
151
 
int my_TIME_to_str(const DRIZZLE_TIME *l_time, char *to);
 
140
int my_time_to_str(const MYSQL_TIME *l_time, char *to);
 
141
int my_date_to_str(const MYSQL_TIME *l_time, char *to);
 
142
int my_datetime_to_str(const MYSQL_TIME *l_time, char *to);
 
143
int my_TIME_to_str(const MYSQL_TIME *l_time, char *to);
152
144
 
153
145
/* 
154
146
  Available interval types used in any statement.
175
167
  INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND, INTERVAL_LAST
176
168
};
177
169
 
178
 
#ifdef __cplusplus
179
 
}
180
 
#endif
 
170
C_MODE_END
181
171
 
182
 
#endif /* _libdrizzle_my_time_h_ */
 
172
#endif /* _my_time_h_ */