~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2009-08-12 06:25:19 UTC
  • mto: (1114.1.1 innodb-plugin-merge)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090812062519-cij02mrrunvnxblt
Tags: innodb-plugin-1.0.4
InnoDB Plugin 1.0.4

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