00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 00003 * 00004 * Copyright (C) 2008-2009 Sun Microsystems, Inc. 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #pragma once 00021 00022 #include <drizzled/sql_error.h> 00023 #include <drizzled/type/time.h> 00024 00025 namespace drizzled 00026 { 00027 /* Calc weekday from daynr */ 00028 /* Returns 0 for monday, 1 for tuesday .... */ 00029 int calc_weekday(long daynr, bool sunday_first_day_of_week); 00030 00031 /* 00032 The bits in week_format has the following meaning: 00033 WEEK_MONDAY_FIRST (0) If not set Sunday is first day of week 00034 If set Monday is first day of week 00035 WEEK_YEAR (1) If not set Week is in range 0-53 00036 00037 Week 0 is returned for the the last week of the previous year (for 00038 a date at start of january) In this case one can get 53 for the 00039 first week of next year. This flag ensures that the week is 00040 relevant for the given year. Note that this flag is only 00041 releveant if WEEK_JANUARY is not set. 00042 00043 If set Week is in range 1-53. 00044 00045 In this case one may get week 53 for a date in January (when 00046 the week is that last week of previous year) and week 1 for a 00047 date in December. 00048 00049 WEEK_FIRST_WEEKDAY (2) If not set Weeks are numbered according 00050 to ISO 8601:1988 00051 If set The week that contains the first 00052 'first-day-of-week' is week 1. 00053 00054 ISO 8601:1988 means that if the week containing January 1 has 00055 four or more days in the new year, then it is week 1; 00056 Otherwise it is the last week of the previous year, and the 00057 next week is week 1. 00058 */ 00059 uint32_t calc_week(type::Time *l_time, uint32_t week_behaviour, uint32_t *year); 00060 00061 /* Change a daynr to year, month and day */ 00062 /* Daynr 0 is returned as date 00.00.00 */ 00063 void get_date_from_daynr(long daynr, 00064 uint32_t *year, 00065 uint32_t *month, 00066 uint32_t *day); 00067 00068 /* 00069 Convert a timestamp string to a type::Time value and produce a warning 00070 if string was truncated during conversion. 00071 00072 NOTE 00073 See description of str_to_datetime() for more information. 00074 */ 00075 type::timestamp_t str_to_datetime_with_warn(Session *session, 00076 const char *str, 00077 uint32_t length, 00078 type::Time *l_time, 00079 uint32_t flags); 00080 00081 /* 00082 Convert a time string to a type::Time struct and produce a warning 00083 if string was cut during conversion. 00084 00085 NOTE 00086 See str_to_time() for more info. 00087 */ 00088 bool str_to_time_with_warn(Session *session, const char *str, uint32_t length, type::Time *l_time); 00089 00090 void make_truncated_value_warning(Session *session, 00091 DRIZZLE_ERROR::enum_warning_level level, 00092 const char *str_val, 00093 uint32_t str_length, 00094 type::timestamp_t time_type, 00095 const char *field_name); 00096 00097 /* 00098 Calculate difference between two datetime values as seconds + microseconds. 00099 00100 SYNOPSIS 00101 calc_time_diff() 00102 l_time1 - TIME/DATE/DATETIME value 00103 l_time2 - TIME/DATE/DATETIME value 00104 l_sign - 1 absolute values are substracted, 00105 -1 absolute values are added. 00106 seconds_out - Out parameter where difference between 00107 l_time1 and l_time2 in seconds is stored. 00108 microseconds_out- Out parameter where microsecond part of difference 00109 between l_time1 and l_time2 is stored. 00110 00111 NOTE 00112 This function calculates difference between l_time1 and l_time2 absolute 00113 values. So one should set l_sign and correct result if he want to take 00114 signs into account (i.e. for type::Time values). 00115 00116 RETURN VALUES 00117 Returns sign of difference. 00118 1 means negative result 00119 0 means positive result 00120 00121 */ 00122 bool calc_time_diff(type::Time *l_time1, 00123 type::Time *l_time2, 00124 int l_sign, 00125 int64_t *seconds_out, 00126 long *microseconds_out); 00127 00128 } /* namespace drizzled */ 00129