1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_TIME_FUNCTIONS_H
21
#define DRIZZLED_TIME_FUNCTIONS_H
23
#include "drizzled/sql_error.h"
24
#include "drizzled/drizzle_time.h"
29
typedef struct st_drizzle_time DRIZZLE_TIME;
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);
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
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.
47
If set Week is in range 1-53.
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
53
WEEK_FIRST_WEEKDAY (2) If not set Weeks are numbered according
55
If set The week that contains the first
56
'first-day-of-week' is week 1.
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
63
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
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,
73
Convert a timestamp string to a DRIZZLE_TIME value and produce a warning
74
if string was truncated during conversion.
77
See description of str_to_datetime() for more information.
79
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str,
85
Convert a time string to a DRIZZLE_TIME struct and produce a warning
86
if string was cut during conversion.
89
See str_to_time() for more info.
91
bool str_to_time_with_warn(const char *str, uint32_t length, DRIZZLE_TIME *l_time);
94
Convert a system time structure to TIME
96
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
98
void make_date(const DRIZZLE_TIME *l_time, String *str);
100
void make_datetime(const DRIZZLE_TIME *l_time, String *str);
102
void make_truncated_value_warning(Session *session,
103
DRIZZLE_ERROR::enum_warning_level level,
106
enum enum_drizzle_timestamp_type time_type,
107
const char *field_name);
110
Calculate difference between two datetime values as seconds + microseconds.
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.
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).
129
Returns sign of difference.
130
1 means negative result
131
0 means positive result
134
bool calc_time_diff(DRIZZLE_TIME *l_time1,
135
DRIZZLE_TIME *l_time2,
137
int64_t *seconds_out,
138
long *microseconds_out);
140
} /* namespace drizzled */
142
#endif /* DRIZZLED_TIME_FUNCTIONS_H */