~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/to_days.cc

  • Committer: Monty Taylor
  • Date: 2008-08-16 21:06:22 UTC
  • Revision ID: monty@inaugust.com-20080816210622-zpnn13unyinqzn72
Updated po files.

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/function/time/to_days.h>
23
 
 
24
 
int64_t Item_func_to_days::val_int()
25
 
{
26
 
  assert(fixed == 1);
27
 
  DRIZZLE_TIME ltime;
28
 
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
29
 
    return 0;
30
 
  return (int64_t) calc_daynr(ltime.year,ltime.month,ltime.day);
31
 
}
32
 
 
33
 
 
34
 
/*
35
 
  Get information about this Item tree monotonicity
36
 
 
37
 
  SYNOPSIS
38
 
    Item_func_to_days::get_monotonicity_info()
39
 
 
40
 
  DESCRIPTION
41
 
  Get information about monotonicity of the function represented by this item
42
 
  tree.
43
 
 
44
 
  RETURN
45
 
    See enum_monotonicity_info.
46
 
*/
47
 
 
48
 
enum_monotonicity_info Item_func_to_days::get_monotonicity_info() const
49
 
{
50
 
  if (args[0]->type() == Item::FIELD_ITEM)
51
 
  {
52
 
    if (args[0]->field_type() == DRIZZLE_TYPE_DATE)
53
 
      return MONOTONIC_STRICT_INCREASING;
54
 
    if (args[0]->field_type() == DRIZZLE_TYPE_DATETIME)
55
 
      return MONOTONIC_INCREASING;
56
 
  }
57
 
  return NON_MONOTONIC;
58
 
}
59
 
 
60
 
int64_t Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
61
 
{
62
 
  assert(fixed == 1);
63
 
  DRIZZLE_TIME ltime;
64
 
  int64_t res;
65
 
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
66
 
  {
67
 
    /* got NULL, leave the incl_endp intact */
68
 
    return INT64_MIN;
69
 
  }
70
 
  res=(int64_t) calc_daynr(ltime.year,ltime.month,ltime.day);
71
 
 
72
 
  if (args[0]->field_type() == DRIZZLE_TYPE_DATE)
73
 
  {
74
 
    // TO_DAYS() is strictly monotonic for dates, leave incl_endp intact
75
 
    return res;
76
 
  }
77
 
 
78
 
  /*
79
 
    Handle the special but practically useful case of datetime values that
80
 
    point to day bound ("strictly less" comparison stays intact):
81
 
 
82
 
      col < '2007-09-15 00:00:00'  -> TO_DAYS(col) <  TO_DAYS('2007-09-15')
83
 
 
84
 
    which is different from the general case ("strictly less" changes to
85
 
    "less or equal"):
86
 
 
87
 
      col < '2007-09-15 12:34:56'  -> TO_DAYS(col) <= TO_DAYS('2007-09-15')
88
 
  */
89
 
  if (!left_endp && !(ltime.hour || ltime.minute || ltime.second ||
90
 
                      ltime.second_part))
91
 
    ; /* do nothing */
92
 
  else
93
 
    *incl_endp= true;
94
 
  return res;
95
 
}
96