~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/time.cc

  • Committer: Stewart Smith
  • Date: 2009-10-19 04:17:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1192.
  • Revision ID: stewart@flamingspork.com-20091019041738-bsjyzmittghcomqj
remove some unused PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP related things as errorcheck mutexes are never used (and haven't been since at least MySQL 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
20
20
 
21
21
/* Functions to handle date and time */
22
22
 
23
 
#include "config.h"
24
 
#include "drizzled/error.h"
25
 
#include "drizzled/util/test.h"
26
 
#include "drizzled/tztime.h"
27
 
#include "drizzled/session.h"
28
 
#include "drizzled/time_functions.h"
29
 
 
30
 
namespace drizzled
31
 
{
 
23
#include <drizzled/server_includes.h>
 
24
#include <drizzled/error.h>
 
25
#include <drizzled/util/test.h>
 
26
#include <drizzled/tztime.h>
 
27
#include <drizzled/session.h>
32
28
 
33
29
/* Some functions to calculate dates */
34
30
 
 
31
#ifndef TESTTIME
 
32
 
 
33
        /* Calc weekday from daynr */
 
34
        /* Returns 0 for monday, 1 for tuesday .... */
35
35
 
36
36
int calc_weekday(long daynr,bool sunday_first_day_of_week)
37
37
{
38
38
  return ((int) ((daynr + 5L + (sunday_first_day_of_week ? 1L : 0L)) % 7));
39
39
}
40
40
 
 
41
/*
 
42
  The bits in week_format has the following meaning:
 
43
   WEEK_MONDAY_FIRST (0)  If not set    Sunday is first day of week
 
44
                          If set        Monday is first day of week
 
45
   WEEK_YEAR (1)          If not set    Week is in range 0-53
 
46
 
 
47
        Week 0 is returned for the the last week of the previous year (for
 
48
        a date at start of january) In this case one can get 53 for the
 
49
        first week of next year.  This flag ensures that the week is
 
50
        relevant for the given year. Note that this flag is only
 
51
        releveant if WEEK_JANUARY is not set.
 
52
 
 
53
                          If set         Week is in range 1-53.
 
54
 
 
55
        In this case one may get week 53 for a date in January (when
 
56
        the week is that last week of previous year) and week 1 for a
 
57
        date in December.
 
58
 
 
59
  WEEK_FIRST_WEEKDAY (2)  If not set    Weeks are numbered according
 
60
                                        to ISO 8601:1988
 
61
                          If set        The week that contains the first
 
62
                                        'first-day-of-week' is week 1.
 
63
 
 
64
        ISO 8601:1988 means that if the week containing January 1 has
 
65
        four or more days in the new year, then it is week 1;
 
66
        Otherwise it is the last week of the previous year, and the
 
67
        next week is week 1.
 
68
*/
41
69
 
42
70
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year)
43
71
{
48
76
  bool week_year= test(week_behaviour & WEEK_YEAR);
49
77
  bool first_weekday= test(week_behaviour & WEEK_FIRST_WEEKDAY);
50
78
 
51
 
  uint32_t weekday= calc_weekday(first_daynr, !monday_first);
 
79
  uint32_t weekday=calc_weekday(first_daynr, !monday_first);
52
80
  *year=l_time->year;
53
81
 
54
82
  if (l_time->month == 1 && l_time->day <= 7-weekday)
79
107
  return days/7+1;
80
108
}
81
109
 
 
110
        /* Change a daynr to year, month and day */
 
111
        /* Daynr 0 is returned as date 00.00.00 */
82
112
 
83
 
void get_date_from_daynr(long daynr,
84
 
                         uint32_t *ret_year,
85
 
                         uint32_t *ret_month,
86
 
                                           uint32_t *ret_day)
 
113
void get_date_from_daynr(long daynr,uint32_t *ret_year,uint32_t *ret_month,
 
114
                         uint32_t *ret_day)
87
115
{
88
116
  uint32_t year,temp,leap_day,day_of_year,days_in_year;
89
117
  unsigned char *month_pos;
123
151
  return;
124
152
}
125
153
 
 
154
/*
 
155
  Convert a timestamp string to a DRIZZLE_TIME value and produce a warning
 
156
  if string was truncated during conversion.
 
157
 
 
158
  NOTE
 
159
    See description of str_to_datetime() for more information.
 
160
*/
126
161
 
127
162
enum enum_drizzle_timestamp_type
128
 
str_to_datetime_with_warn(const char *str, 
129
 
                          uint32_t length, 
130
 
                          DRIZZLE_TIME *l_time,
 
163
str_to_datetime_with_warn(const char *str, uint32_t length, DRIZZLE_TIME *l_time,
131
164
                          uint32_t flags)
132
165
{
133
166
  int was_cut;
 
167
  Session *session= current_session;
134
168
  enum enum_drizzle_timestamp_type ts_type;
135
 
  Session *session= current_session;
136
169
 
137
170
  ts_type= str_to_datetime(str, length, l_time,
138
171
                           (flags | (session->variables.sql_mode &
140
173
                                      MODE_NO_ZERO_DATE))),
141
174
                           &was_cut);
142
175
  if (was_cut || ts_type <= DRIZZLE_TIMESTAMP_ERROR)
143
 
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
176
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
144
177
                                 str, length, ts_type,  NULL);
145
178
  return ts_type;
146
179
}
147
180
 
 
181
/*
 
182
  Convert a time string to a DRIZZLE_TIME struct and produce a warning
 
183
  if string was cut during conversion.
148
184
 
 
185
  NOTE
 
186
    See str_to_time() for more info.
 
187
*/
149
188
bool
150
189
str_to_time_with_warn(const char *str, uint32_t length, DRIZZLE_TIME *l_time)
151
190
{
158
197
}
159
198
 
160
199
 
 
200
/*
 
201
  Convert a system time structure to TIME
 
202
*/
 
203
 
161
204
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from)
162
205
{
163
206
  to->neg=0;
188
231
}
189
232
 
190
233
 
191
 
void make_truncated_value_warning(Session *session, 
192
 
                                  DRIZZLE_ERROR::enum_warning_level level,
 
234
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
193
235
                                  const char *str_val,
194
 
                                                          uint32_t str_length,
 
236
                                  uint32_t str_length,
195
237
                                  enum enum_drizzle_timestamp_type time_type,
196
238
                                  const char *field_name)
197
239
{
216
258
      break;
217
259
  }
218
260
  if (field_name)
219
 
  {
220
261
    cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
221
262
                       ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
222
263
                       type_str, str.c_ptr(), field_name,
223
264
                       (uint32_t) session->row_count);
224
 
  }
225
265
  else
226
266
  {
227
267
    if (time_type > DRIZZLE_TIMESTAMP_ERROR)
236
276
               ER_TRUNCATED_WRONG_VALUE, warn_buff);
237
277
}
238
278
 
 
279
/*
 
280
  Calculate difference between two datetime values as seconds + microseconds.
 
281
 
 
282
  SYNOPSIS
 
283
    calc_time_diff()
 
284
      l_time1         - TIME/DATE/DATETIME value
 
285
      l_time2         - TIME/DATE/DATETIME value
 
286
      l_sign          - 1 absolute values are substracted,
 
287
                        -1 absolute values are added.
 
288
      seconds_out     - Out parameter where difference between
 
289
                        l_time1 and l_time2 in seconds is stored.
 
290
      microseconds_out- Out parameter where microsecond part of difference
 
291
                        between l_time1 and l_time2 is stored.
 
292
 
 
293
  NOTE
 
294
    This function calculates difference between l_time1 and l_time2 absolute
 
295
    values. So one should set l_sign and correct result if he want to take
 
296
    signs into account (i.e. for DRIZZLE_TIME values).
 
297
 
 
298
  RETURN VALUES
 
299
    Returns sign of difference.
 
300
    1 means negative result
 
301
    0 means positive result
 
302
 
 
303
*/
239
304
 
240
305
bool
241
306
calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign, int64_t *seconds_out,
286
351
  return neg;
287
352
}
288
353
 
289
 
} /* namespace drizzled */
 
354
 
 
355
#endif