1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
8
* Clint Byrum <clint@fewbar.com>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; version 2 of the License.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
#ifndef DRIZZLED_TEMPORAL_INTERVAL_H
25
#define DRIZZLED_TEMPORAL_INTERVAL_H
27
/* @TODO Replace this include with some forward decls */
28
#include "drizzled/item.h"
35
* Stores time interval for date/time manipulation
37
class TemporalInterval
41
TemporalInterval(uint32_t in_year,
47
uint64_t in_second_part,
56
second_part(in_second_part),
73
* Sets whether or not this object specifies a negative interval
74
* @param[in] in_neg true if this is a negative interval, false if not
76
void setNegative(bool in_neg= true)
82
* reverse boolean value of the negative flag
90
* @retval true this is a negative temporal interval
91
* @retval false this is a positive temporal interval
93
bool getNegative() const
99
* Populate this TemporalInterval from a string value
101
* To make code easy, allow interval objects without separators.
103
* @param args argument Item structure
104
* @param int_type type of interval to create
105
* @param str_value String pointer to the input value
106
* @return true if the string would result in a null interval
109
bool initFromItem(Item *args, interval_type int_type, String *str_value);
112
* Adds this interval to a DRIZZLE_LTIME structure
114
* @param[in,out] ltime the interval will be added to ltime directly in the ltime structure
115
* @param[in] int_type the type of interval requested
116
* @retval true date was added and value stored properly
117
* @retval false result of addition is a null value
119
bool addDate(DRIZZLE_TIME *ltime, interval_type int_type);
124
* The maximum number of text elements to extract into a temporal interval
126
static const uint32_t MAX_STRING_ELEMENTS = 5;
129
* Each of these corresponds to an 'interval_type'
131
static const uint32_t NUM_YEAR_MONTH_STRING_ELEMENTS = 2;
132
static const uint32_t NUM_DAY_HOUR_STRING_ELEMENTS = 2;
133
static const uint32_t NUM_DAY_MICROSECOND_STRING_ELEMENTS = 5;
134
static const uint32_t NUM_DAY_MINUTE_STRING_ELEMENTS = 3;
135
static const uint32_t NUM_DAY_SECOND_STRING_ELEMENTS = 4;
136
static const uint32_t NUM_HOUR_MICROSECOND_STRING_ELEMENTS = 4;
137
static const uint32_t NUM_HOUR_MINUTE_STRING_ELEMENTS = 2;
138
static const uint32_t NUM_HOUR_SECOND_STRING_ELEMENTS = 3;
139
static const uint32_t NUM_MINUTE_MICROSECOND_STRING_ELEMENTS = 3;
140
static const uint32_t NUM_MINUTE_SECOND_STRING_ELEMENTS = 2;
141
static const uint32_t NUM_SECOND_MICROSECOND_STRING_ELEMENTS = 2;
145
* Get a array of positive numbers from a string object.
146
* Each number is separated by 1 non digit character
147
* Return error if there is too many numbers.
148
* If there is too few numbers, assume that the numbers are left out
149
* from the high end. This allows one to give:
150
* DAY_TO_SECOND as "D MM:HH:SS", "MM:HH:SS" "HH:SS" or as seconds.
152
* @param[in] length: length of str
153
* @param[in] cs: charset of str
154
* @param[out] values: array of results
155
* @param[out] count: count of elements in result array
156
* @param transform_msec: if value is true we suppose
157
* that the last part of string value is microseconds
158
* and we should transform value to six digit value.
159
* For example, '1.1' -> '1.100000'
161
bool getIntervalFromString(const char *str,
163
const CHARSET_INFO * const cs,
166
bool transform_msec);
174
uint64_t second_part;
179
} /* end namespace drizzled */
181
#endif /* DRIZZLED_TEMPORAL_INTERVAL_H */