1237.9.4
by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008-2009 Sun Microsystems
|
|
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; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
1237.9.8
by Monty Taylor
Fixed solaris build. |
20 |
#ifndef DRIZZLED_TIME_FUNCTIONS_H
|
21 |
#define DRIZZLED_TIME_FUNCTIONS_H
|
|
1237.9.4
by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file. |
22 |
|
23 |
#include "drizzled/sql_error.h" |
|
1241.9.53
by Monty Taylor
Drizzle_time is part of the API. |
24 |
#include "drizzled/my_time.h" |
1237.9.4
by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file. |
25 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
26 |
namespace drizzled |
27 |
{
|
|
28 |
||
1237.9.4
by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file. |
29 |
typedef struct st_drizzle_time DRIZZLE_TIME; |
30 |
||
31 |
/* Calc weekday from daynr */
|
|
32 |
/* Returns 0 for monday, 1 for tuesday .... */
|
|
33 |
int calc_weekday(long daynr, bool sunday_first_day_of_week); |
|
34 |
||
35 |
/*
|
|
36 |
The bits in week_format has the following meaning:
|
|
37 |
WEEK_MONDAY_FIRST (0) If not set Sunday is first day of week
|
|
38 |
If set Monday is first day of week
|
|
39 |
WEEK_YEAR (1) If not set Week is in range 0-53
|
|
40 |
||
41 |
Week 0 is returned for the the last week of the previous year (for
|
|
42 |
a date at start of january) In this case one can get 53 for the
|
|
43 |
first week of next year. This flag ensures that the week is
|
|
44 |
relevant for the given year. Note that this flag is only
|
|
45 |
releveant if WEEK_JANUARY is not set.
|
|
46 |
||
47 |
If set Week is in range 1-53.
|
|
48 |
||
49 |
In this case one may get week 53 for a date in January (when
|
|
50 |
the week is that last week of previous year) and week 1 for a
|
|
51 |
date in December.
|
|
52 |
||
53 |
WEEK_FIRST_WEEKDAY (2) If not set Weeks are numbered according
|
|
54 |
to ISO 8601:1988
|
|
55 |
If set The week that contains the first
|
|
56 |
'first-day-of-week' is week 1.
|
|
57 |
||
58 |
ISO 8601:1988 means that if the week containing January 1 has
|
|
59 |
four or more days in the new year, then it is week 1;
|
|
60 |
Otherwise it is the last week of the previous year, and the
|
|
61 |
next week is week 1.
|
|
62 |
*/
|
|
63 |
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year); |
|
64 |
||
65 |
/* Change a daynr to year, month and day */
|
|
66 |
/* Daynr 0 is returned as date 00.00.00 */
|
|
67 |
void get_date_from_daynr(long daynr, |
|
68 |
uint32_t *year, |
|
69 |
uint32_t *month, |
|
70 |
uint32_t *day); |
|
71 |
||
72 |
/*
|
|
73 |
Convert a timestamp string to a DRIZZLE_TIME value and produce a warning
|
|
74 |
if string was truncated during conversion.
|
|
75 |
||
76 |
NOTE
|
|
77 |
See description of str_to_datetime() for more information.
|
|
78 |
*/
|
|
79 |
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, |
|
80 |
uint32_t length, |
|
81 |
DRIZZLE_TIME *l_time, |
|
82 |
uint32_t flags); |
|
83 |
||
84 |
/*
|
|
85 |
Convert a time string to a DRIZZLE_TIME struct and produce a warning
|
|
86 |
if string was cut during conversion.
|
|
87 |
||
88 |
NOTE
|
|
89 |
See str_to_time() for more info.
|
|
90 |
*/
|
|
91 |
bool str_to_time_with_warn(const char *str, uint32_t length, DRIZZLE_TIME *l_time); |
|
92 |
||
93 |
/*
|
|
94 |
Convert a system time structure to TIME
|
|
95 |
*/
|
|
96 |
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from); |
|
97 |
||
98 |
void make_date(const DRIZZLE_TIME *l_time, String *str); |
|
99 |
||
100 |
void make_datetime(const DRIZZLE_TIME *l_time, String *str); |
|
101 |
||
102 |
void make_truncated_value_warning(Session *session, |
|
103 |
DRIZZLE_ERROR::enum_warning_level level, |
|
104 |
const char *str_val, |
|
105 |
uint32_t str_length, |
|
106 |
enum enum_drizzle_timestamp_type time_type, |
|
107 |
const char *field_name); |
|
108 |
||
109 |
/*
|
|
110 |
Calculate difference between two datetime values as seconds + microseconds.
|
|
111 |
||
112 |
SYNOPSIS
|
|
113 |
calc_time_diff()
|
|
114 |
l_time1 - TIME/DATE/DATETIME value
|
|
115 |
l_time2 - TIME/DATE/DATETIME value
|
|
116 |
l_sign - 1 absolute values are substracted,
|
|
117 |
-1 absolute values are added.
|
|
118 |
seconds_out - Out parameter where difference between
|
|
119 |
l_time1 and l_time2 in seconds is stored.
|
|
120 |
microseconds_out- Out parameter where microsecond part of difference
|
|
121 |
between l_time1 and l_time2 is stored.
|
|
122 |
||
123 |
NOTE
|
|
124 |
This function calculates difference between l_time1 and l_time2 absolute
|
|
125 |
values. So one should set l_sign and correct result if he want to take
|
|
126 |
signs into account (i.e. for DRIZZLE_TIME values).
|
|
127 |
||
128 |
RETURN VALUES
|
|
129 |
Returns sign of difference.
|
|
130 |
1 means negative result
|
|
131 |
0 means positive result
|
|
132 |
||
133 |
*/
|
|
134 |
bool calc_time_diff(DRIZZLE_TIME *l_time1, |
|
135 |
DRIZZLE_TIME *l_time2, |
|
136 |
int l_sign, |
|
137 |
int64_t *seconds_out, |
|
138 |
long *microseconds_out); |
|
139 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
140 |
} /* namespace drizzled */ |
141 |
||
1237.9.8
by Monty Taylor
Fixed solaris build. |
142 |
#endif /* DRIZZLED_TIME_FUNCTIONS_H */ |