~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal_interval.h

  • Committer: clint at fewbar
  • Date: 2009-07-21 17:13:11 UTC
  • mto: (1093.1.33 captain)
  • mto: This revision was merged to the branch mainline in revision 1105.
  • Revision ID: clint@fewbar.com-20090721171311-gacvpc1piussubxr
refactoring INTERVAL into C++ class

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <drizzled/item.h>
 
2
 
 
3
namespace drizzled {
 
4
  /**
 
5
   *  Stores time interval for date/time manipulation
 
6
   */
 
7
  class TemporalInterval
 
8
  {
 
9
    public:
 
10
      TemporalInterval(uint32_t in_year,
 
11
          uint32_t in_month,
 
12
          uint32_t in_day,
 
13
          uint32_t in_hour,
 
14
          uint64_t in_minute,
 
15
          uint64_t in_second,
 
16
          uint64_t in_second_part,
 
17
          bool in_neg)
 
18
        :
 
19
          year(in_year),
 
20
          month(in_month),
 
21
          day(in_day),
 
22
          hour(in_hour),
 
23
          minute(in_minute),
 
24
          second(in_second),
 
25
          second_part(in_second_part),
 
26
          neg(in_neg)
 
27
    {}
 
28
 
 
29
      TemporalInterval()
 
30
        :
 
31
          year(0),
 
32
          month(0),
 
33
          day(0),
 
34
          hour(0),
 
35
          minute(0),
 
36
          second(0),
 
37
          second_part(0),
 
38
          neg(false)
 
39
    {}
 
40
 
 
41
      /**
 
42
       * Sets whether or not this object specifies a negative interval
 
43
       * @param[in] in_neg true if this is a negative interval, false if not
 
44
       */
 
45
      void setNegative(bool in_neg=true)
 
46
      {
 
47
        neg = in_neg;
 
48
      }
 
49
 
 
50
      bool getNeg() const
 
51
      {
 
52
        return neg;
 
53
      }
 
54
 
 
55
      /**
 
56
       * Populate this TemporalInterval from a string value
 
57
       *
 
58
       * To make code easy, allow interval objects without separators.
 
59
       *
 
60
       * @param args argument Item structure
 
61
       * @param int_type type of interval to create
 
62
       * @param str_value String pointer to the input value
 
63
       * @return true if the string would result in a null interval
 
64
       * 
 
65
       */
 
66
      bool value_from_item(Item *args, interval_type int_type, String *str_value);
 
67
 
 
68
      /**
 
69
       * Adds this interval to a DRIZZLE_LTIME structure
 
70
       *
 
71
       * @param[in,out] ltime the interval will be added to ltime directly in the ltime structure
 
72
       * @param[in] int_type the type of interval requested
 
73
       * @retval true date was added and value stored properly
 
74
       * @retval false result of addition is a null value
 
75
       */
 
76
      bool add_date(DRIZZLE_TIME *ltime, interval_type int_type);
 
77
 
 
78
    private:
 
79
 
 
80
      /**
 
81
       *  @details
 
82
       *  Get a array of positive numbers from a string object.
 
83
       *  Each number is separated by 1 non digit character
 
84
       *  Return error if there is too many numbers.
 
85
       *  If there is too few numbers, assume that the numbers are left out
 
86
       *  from the high end. This allows one to give:
 
87
       *  DAY_TO_SECOND as "D MM:HH:SS", "MM:HH:SS" "HH:SS" or as seconds.
 
88
 
 
89
       *  @param length:         length of str
 
90
       *  @param cs:             charset of str
 
91
       *  @param values:         array of results
 
92
       *  @param count:          count of elements in result array
 
93
       *  @param transform_msec: if value is true we suppose
 
94
       *  that the last part of string value is microseconds
 
95
       *  and we should transform value to six digit value.
 
96
       *  For example, '1.1' -> '1.100000'
 
97
       */
 
98
      bool get_interval_info(const char *str,uint32_t length, const CHARSET_INFO * const cs,
 
99
          uint32_t count, uint64_t *values,
 
100
          bool transform_msec);
 
101
 
 
102
      uint32_t  year;
 
103
      uint32_t  month;
 
104
      uint32_t  day;
 
105
      uint32_t  hour;
 
106
      uint64_t  minute;
 
107
      uint64_t  second;
 
108
      uint64_t  second_part;
 
109
      bool      neg;
 
110
 
 
111
  };
 
112
}