Drizzled Public API Documentation

time_functions.h
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, Inc.
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 
20 #pragma once
21 
22 #include <drizzled/sql_error.h>
23 #include <drizzled/type/time.h>
24 
25 namespace drizzled
26 {
27 /* Calc weekday from daynr */
28 /* Returns 0 for monday, 1 for tuesday .... */
29 int calc_weekday(long daynr, bool sunday_first_day_of_week);
30 
31 /*
32  The bits in week_format has the following meaning:
33  WEEK_MONDAY_FIRST (0) If not set Sunday is first day of week
34  If set Monday is first day of week
35  WEEK_YEAR (1) If not set Week is in range 0-53
36 
37  Week 0 is returned for the the last week of the previous year (for
38  a date at start of january) In this case one can get 53 for the
39  first week of next year. This flag ensures that the week is
40  relevant for the given year. Note that this flag is only
41  releveant if WEEK_JANUARY is not set.
42 
43  If set Week is in range 1-53.
44 
45  In this case one may get week 53 for a date in January (when
46  the week is that last week of previous year) and week 1 for a
47  date in December.
48 
49  WEEK_FIRST_WEEKDAY (2) If not set Weeks are numbered according
50  to ISO 8601:1988
51  If set The week that contains the first
52  'first-day-of-week' is week 1.
53 
54  ISO 8601:1988 means that if the week containing January 1 has
55  four or more days in the new year, then it is week 1;
56  Otherwise it is the last week of the previous year, and the
57  next week is week 1.
58 */
59 uint32_t calc_week(type::Time *l_time, uint32_t week_behaviour, uint32_t *year);
60 
61 /* Change a daynr to year, month and day */
62 /* Daynr 0 is returned as date 00.00.00 */
63 void get_date_from_daynr(long daynr,
64  uint32_t *year,
65  uint32_t *month,
66  uint32_t *day);
67 
68 /*
69  Convert a timestamp string to a type::Time value and produce a warning
70  if string was truncated during conversion.
71 
72  NOTE
73  See description of str_to_datetime() for more information.
74 */
75 type::timestamp_t str_to_datetime_with_warn(Session&, str_ref, type::Time&, uint32_t flags);
76 
77 /*
78  Convert a time string to a type::Time struct and produce a warning
79  if string was cut during conversion.
80 
81  NOTE
82  See str_to_time() for more info.
83 */
84 bool str_to_time_with_warn(Session&, str_ref, type::Time&);
85 
86 void make_truncated_value_warning(Session&, DRIZZLE_ERROR::enum_warning_level level, str_ref, type::timestamp_t, const char* field);
87 
88 /*
89  Calculate difference between two datetime values as seconds + microseconds.
90 
91  SYNOPSIS
92  calc_time_diff()
93  l_time1 - TIME/DATE/DATETIME value
94  l_time2 - TIME/DATE/DATETIME value
95  l_sign - 1 absolute values are substracted,
96  -1 absolute values are added.
97  seconds_out - Out parameter where difference between
98  l_time1 and l_time2 in seconds is stored.
99  microseconds_out- Out parameter where microsecond part of difference
100  between l_time1 and l_time2 is stored.
101 
102  NOTE
103  This function calculates difference between l_time1 and l_time2 absolute
104  values. So one should set l_sign and correct result if he want to take
105  signs into account (i.e. for type::Time values).
106 
107  RETURN VALUES
108  Returns sign of difference.
109  1 means negative result
110  0 means positive result
111 
112 */
113 bool calc_time_diff(type::Time *l_time1,
114  type::Time *l_time2,
115  int l_sign,
116  int64_t *seconds_out,
117  long *microseconds_out);
118 
119 } /* namespace drizzled */
120 
TODO: Rename this file - func.h is stupid.