~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/time/week.cc

  • Committer: Brian Aker
  • Date: 2008-11-13 02:56:15 UTC
  • mfrom: (575.4.10 devel)
  • Revision ID: brian@tangent.org-20081113025615-snhsi52yb2ivmx6f
Merging Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 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
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include <drizzled/functions/time/week.h>
 
23
 
 
24
/**
 
25
 @verbatim
 
26
  The bits in week_format(for calc_week() function) has the following meaning:
 
27
   WEEK_MONDAY_FIRST (0)  If not set    Sunday is first day of week
 
28
                          If set        Monday is first day of week
 
29
   WEEK_YEAR (1)          If not set    Week is in range 0-53
 
30
 
 
31
        Week 0 is returned for the the last week of the previous year (for
 
32
        a date at start of january) In this case one can get 53 for the
 
33
        first week of next year.  This flag ensures that the week is
 
34
        relevant for the given year. Note that this flag is only
 
35
        releveant if WEEK_JANUARY is not set.
 
36
 
 
37
                          If set         Week is in range 1-53.
 
38
 
 
39
        In this case one may get week 53 for a date in January (when
 
40
        the week is that last week of previous year) and week 1 for a
 
41
        date in December.
 
42
 
 
43
  WEEK_FIRST_WEEKDAY (2)  If not set    Weeks are numbered according
 
44
                                        to ISO 8601:1988
 
45
                          If set        The week that contains the first
 
46
                                        'first-day-of-week' is week 1.
 
47
 
 
48
        ISO 8601:1988 means that if the week containing January 1 has
 
49
        four or more days in the new year, then it is week 1;
 
50
        Otherwise it is the last week of the previous year, and the
 
51
        next week is week 1.
 
52
 @endverbatim
 
53
*/
 
54
 
 
55
int64_t Item_func_week::val_int()
 
56
{
 
57
  assert(fixed == 1);
 
58
  uint32_t year;
 
59
  DRIZZLE_TIME ltime;
 
60
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
 
61
    return 0;
 
62
  return (int64_t) calc_week(&ltime,
 
63
                              week_mode((uint) args[1]->val_int()),
 
64
                              &year);
 
65
}
 
66
 
 
67