~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to unittests/temporal_generator.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install 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) 2010 Pawel Blokus
 
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; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <drizzled/temporal.h>
 
24
#include <drizzled/temporal_format.h>
 
25
#include <drizzled/temporal_interval.h>
 
26
 
 
27
#include "temporal_generator.h"
 
28
 
 
29
using namespace drizzled;
 
30
 
 
31
void TemporalGenerator::DateGen::make_date(Date *date,
 
32
                                          uint32_t years, uint32_t months, uint32_t days)
 
33
{
 
34
  date->set_years(years);
 
35
  date->set_months(months);
 
36
  date->set_days(days);
 
37
  date->set_epoch_seconds();
 
38
}
 
39
 
 
40
void TemporalGenerator::DateGen::make_valid_date(drizzled::Date *date)
 
41
{
 
42
  date->set_years(2005);
 
43
  date->set_months(5);
 
44
  date->set_days(26);
 
45
  date->set_epoch_seconds();
 
46
}
 
47
 
 
48
void TemporalGenerator::TemporalGen::leap_day_in_leap_year(drizzled::Temporal *temporal)
 
49
{
 
50
  temporal->set_years(2008);
 
51
  temporal->set_months(2);
 
52
  temporal->set_days(29);
 
53
  temporal->set_epoch_seconds();
 
54
}
 
55
 
 
56
void TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(drizzled::Temporal *temporal)
 
57
{
 
58
  temporal->set_years(2010);
 
59
  temporal->set_months(2);
 
60
  temporal->set_days(29);
 
61
  temporal->set_epoch_seconds();
 
62
}
 
63
 
 
64
void TemporalGenerator::TimeGen::make_time(drizzled::Time *time,
 
65
                                   uint32_t hours, uint32_t minutes, uint32_t seconds,
 
66
                                   uint32_t useconds)
 
67
{
 
68
  time->set_hours(hours);
 
69
  time->set_minutes(minutes);
 
70
  time->set_seconds(seconds);
 
71
  time->set_useconds(useconds);
 
72
  time->set_epoch_seconds();
 
73
}
 
74
 
 
75
void TemporalGenerator::TemporalGen::make_min_time(drizzled::Temporal *temporal)
 
76
{
 
77
  temporal->set_hours(0);
 
78
  temporal->set_minutes(0);
 
79
  temporal->set_seconds(0);
 
80
  temporal->set_epoch_seconds();
 
81
}
 
82
 
 
83
void TemporalGenerator::TemporalGen::make_max_time(drizzled::Temporal *temporal)
 
84
{
 
85
  temporal->set_hours(23);
 
86
  temporal->set_minutes(59);
 
87
  temporal->set_seconds(59);
 
88
  temporal->set_epoch_seconds();
 
89
}
 
90
 
 
91
void TemporalGenerator::DateTimeGen::make_datetime(drizzled::DateTime *datetime,
 
92
                   uint32_t years, uint32_t months, uint32_t days, uint32_t hours,
 
93
                   uint32_t minutes, uint32_t seconds, uint32_t useconds)
 
94
{
 
95
  datetime->set_years(years);
 
96
  datetime->set_months(months);
 
97
  datetime->set_days(days);
 
98
  datetime->set_hours(hours);
 
99
  datetime->set_minutes(minutes);
 
100
  datetime->set_seconds(seconds);
 
101
  datetime->set_useconds(useconds);
 
102
  datetime->set_epoch_seconds();
 
103
}                     
 
104
 
 
105
void TemporalGenerator::DateTimeGen::make_valid_datetime(drizzled::DateTime *datetime)
 
106
{
 
107
  datetime->set_years(1999);
 
108
  datetime->set_months(8);
 
109
  datetime->set_days(15);
 
110
  datetime->set_hours(13);
 
111
  datetime->set_minutes(34);
 
112
  datetime->set_seconds(6);
 
113
  datetime->set_epoch_seconds();
 
114
}
 
115
 
 
116
void TemporalGenerator::TimestampGen::make_timestamp(drizzled::Timestamp *timestamp,
 
117
                                             uint32_t years, uint32_t months, uint32_t days,
 
118
                                             uint32_t hours, uint32_t minutes, uint32_t seconds)
 
119
{
 
120
  timestamp->set_years(years);
 
121
  timestamp->set_months(months);
 
122
  timestamp->set_days(days);
 
123
  timestamp->set_hours(hours);
 
124
  timestamp->set_minutes(minutes);
 
125
  timestamp->set_seconds(seconds);
 
126
  timestamp->set_epoch_seconds();
 
127
}
 
128
 
 
129
void TemporalGenerator::TimestampGen::make_micro_timestamp(drizzled::MicroTimestamp *timestamp,
 
130
                                                   uint32_t years, uint32_t months, uint32_t days,
 
131
                                                   uint32_t hours, uint32_t minutes,
 
132
                                                   uint32_t seconds, uint32_t microseconds)
 
133
{
 
134
  make_timestamp(timestamp, years, months, days, hours, minutes, seconds);
 
135
  timestamp->set_useconds(microseconds);
 
136
  timestamp->set_epoch_seconds();
 
137
}
 
138
                                 
 
139
void TemporalGenerator::TimestampGen::make_nano_timestamp(drizzled::NanoTimestamp *timestamp,
 
140
                                                  uint32_t years, uint32_t months, uint32_t days,
 
141
                                                  uint32_t hours, uint32_t minutes,
 
142
                                                  uint32_t seconds, uint32_t nanoseconds)
 
143
{
 
144
  make_timestamp(timestamp, years, months, days, hours, minutes, seconds);
 
145
  timestamp->set_nseconds(nanoseconds);
 
146
  timestamp->set_epoch_seconds();
 
147
}
 
148
 
 
149
drizzled::TemporalFormat *TemporalGenerator::TemporalFormatGen::make_temporal_format(const char *regexp,
 
150
                                                                  int32_t year_part_index,
 
151
                                                                  int32_t month_part_index,
 
152
                                                                  int32_t day_part_index,
 
153
                                                                  int32_t hour_part_index,
 
154
                                                                  int32_t minute_part_index,
 
155
                                                                  int32_t second_part_index,
 
156
                                                                  int32_t usecond_part_index,
 
157
                                                                  int32_t nsecond_part_index)
 
158
{
 
159
  drizzled::TemporalFormat *temporal_format= new drizzled::TemporalFormat(regexp);
 
160
  
 
161
  temporal_format->set_year_part_index(year_part_index);
 
162
  temporal_format->set_month_part_index(month_part_index);
 
163
  temporal_format->set_day_part_index(day_part_index);
 
164
  temporal_format->set_hour_part_index(hour_part_index);
 
165
  temporal_format->set_minute_part_index(minute_part_index);
 
166
  temporal_format->set_second_part_index(second_part_index);
 
167
  temporal_format->set_usecond_part_index(usecond_part_index);
 
168
  temporal_format->set_nsecond_part_index(nsecond_part_index);
 
169
 
 
170
  return temporal_format;
 
171
}
 
172
 
 
173
drizzled::TemporalInterval *TemporalGenerator::TemporalIntervalGen::make_temporal_interval(
 
174
                                                              uint32_t  year,
 
175
                                                              uint32_t  month,
 
176
                                                              uint32_t  day,
 
177
                                                              uint32_t  hour,
 
178
                                                              uint64_t  minute,
 
179
                                                              uint64_t  second,
 
180
                                                              uint64_t  second_part,
 
181
                                                              bool neg)
 
182
{
 
183
  drizzled::TemporalInterval *interval= new drizzled::TemporalInterval();
 
184
 
 
185
  interval->set_year(year);
 
186
  interval->set_month(month);
 
187
  interval->set_day(day);
 
188
  interval->set_hour(hour);
 
189
  interval->set_minute(minute);
 
190
  interval->set_second(second);
 
191
  interval->set_second_part(second_part);
 
192
  interval->setNegative(neg);
 
193
 
 
194
  return interval;
 
195
}