~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/my_time.h

  • Committer: Brian Aker
  • Date: 2008-07-31 19:57:34 UTC
  • mfrom: (236.1.27 codestyle)
  • Revision ID: brian@tangent.org-20080731195734-c7cu4gx70xgjr68o
Merge from Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
 
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
 */
15
20
 
16
21
/*
17
22
  This is a private header of sql-common library, containing
18
23
  declarations for my_time.c
19
24
*/
20
25
 
21
 
#ifndef _my_time_h_
22
 
#define _my_time_h_
 
26
#ifndef _libdrizzle_my_time_h_
 
27
#define _libdrizzle_my_time_h_
 
28
 
23
29
#include "drizzled/global.h"
24
30
#include "drizzle_time.h"
25
31
 
61
67
#define TIME_NO_ZERO_DATE       (TIME_NO_ZERO_IN_DATE*2)
62
68
#define TIME_INVALID_DATES      (TIME_NO_ZERO_DATE*2)
63
69
 
64
 
#define MYSQL_TIME_WARN_TRUNCATED    1
65
 
#define MYSQL_TIME_WARN_OUT_OF_RANGE 2
 
70
#define DRIZZLE_TIME_WARN_TRUNCATED    1
 
71
#define DRIZZLE_TIME_WARN_OUT_OF_RANGE 2
66
72
 
67
73
/* Limits for the TIME data type */
68
74
#define TIME_MAX_HOUR 838
73
79
#define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \
74
80
                                TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
75
81
 
76
 
my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date,
 
82
bool check_date(const DRIZZLE_TIME *ltime, bool not_zero_date,
77
83
                   ulong flags, int *was_cut);
78
 
enum enum_mysql_timestamp_type
79
 
str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
 
84
enum enum_drizzle_timestamp_type
 
85
str_to_datetime(const char *str, uint length, DRIZZLE_TIME *l_time,
80
86
                uint flags, int *was_cut);
81
 
int64_t number_to_datetime(int64_t nr, MYSQL_TIME *time_res,
 
87
int64_t number_to_datetime(int64_t nr, DRIZZLE_TIME *time_res,
82
88
                            uint flags, int *was_cut);
83
 
uint64_t TIME_to_uint64_t_datetime(const MYSQL_TIME *);
84
 
uint64_t TIME_to_uint64_t_date(const MYSQL_TIME *);
85
 
uint64_t TIME_to_uint64_t_time(const MYSQL_TIME *);
86
 
uint64_t TIME_to_uint64_t(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);
 
89
uint64_t TIME_to_uint64_t_datetime(const DRIZZLE_TIME *);
 
90
uint64_t TIME_to_uint64_t_date(const DRIZZLE_TIME *);
 
91
uint64_t TIME_to_uint64_t_time(const DRIZZLE_TIME *);
 
92
uint64_t TIME_to_uint64_t(const DRIZZLE_TIME *);
 
93
 
 
94
 
 
95
bool str_to_time(const char *str,uint length, DRIZZLE_TIME *l_time,
 
96
                 int *warning);
 
97
 
 
98
int check_time_range(DRIZZLE_TIME *my_time, int *warning);
93
99
 
94
100
long calc_daynr(uint year,uint month,uint day);
95
101
uint calc_days_in_year(uint year);
102
108
  Function to check sanity of a TIMESTAMP value
103
109
 
104
110
  DESCRIPTION
105
 
    Check if a given MYSQL_TIME value fits in TIMESTAMP range.
 
111
    Check if a given DRIZZLE_TIME value fits in TIMESTAMP range.
106
112
    This function doesn't make precise check, but rather a rough
107
113
    estimate.
108
114
 
109
115
  RETURN VALUES
110
116
    false   The value seems sane
111
 
    true    The MYSQL_TIME value is definitely out of range
 
117
    true    The DRIZZLE_TIME value is definitely out of range
112
118
*/
113
119
 
114
 
static inline my_bool validate_timestamp_range(const MYSQL_TIME *t)
 
120
static inline bool validate_timestamp_range(const DRIZZLE_TIME *t)
115
121
{
116
122
  if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
117
123
      (t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
122
128
}
123
129
 
124
130
my_time_t 
125
 
my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone,
 
131
my_system_gmt_sec(const DRIZZLE_TIME *t, long *my_timezone,
126
132
                  bool *in_dst_time_gap);
127
133
 
128
 
void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type);
 
134
void set_zero_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type time_type);
129
135
 
130
136
/*
131
137
  Required buffer length for my_time_to_str, my_date_to_str,
137
143
*/
138
144
#define MAX_DATE_STRING_REP_LENGTH 30
139
145
 
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);
 
146
int my_time_to_str(const DRIZZLE_TIME *l_time, char *to);
 
147
int my_date_to_str(const DRIZZLE_TIME *l_time, char *to);
 
148
int my_datetime_to_str(const DRIZZLE_TIME *l_time, char *to);
 
149
int my_TIME_to_str(const DRIZZLE_TIME *l_time, char *to);
144
150
 
145
151
/* 
146
152
  Available interval types used in any statement.
169
175
 
170
176
C_MODE_END
171
177
 
172
 
#endif /* _my_time_h_ */
 
178
#endif /* _libdrizzle_my_time_h_ */