1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Pawel Blokus
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.
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.
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
23
#include <drizzled/temporal.h>
24
#include <drizzled/temporal_format.h>
25
#include <drizzled/temporal_interval.h>
27
#include "temporal_generator.h"
29
using namespace drizzled;
31
void TemporalGenerator::DateGen::make_date(Date *date,
32
uint32_t years, uint32_t months, uint32_t days)
34
date->set_years(years);
35
date->set_months(months);
37
date->set_epoch_seconds();
40
void TemporalGenerator::DateGen::make_valid_date(drizzled::Date *date)
42
date->set_years(2005);
45
date->set_epoch_seconds();
48
void TemporalGenerator::TemporalGen::leap_day_in_leap_year(drizzled::Temporal *temporal)
50
temporal->set_years(2008);
51
temporal->set_months(2);
52
temporal->set_days(29);
53
temporal->set_epoch_seconds();
56
void TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(drizzled::Temporal *temporal)
58
temporal->set_years(2010);
59
temporal->set_months(2);
60
temporal->set_days(29);
61
temporal->set_epoch_seconds();
64
void TemporalGenerator::TimeGen::make_time(drizzled::Time *time,
65
uint32_t hours, uint32_t minutes, uint32_t seconds,
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();
75
void TemporalGenerator::TemporalGen::make_min_time(drizzled::Temporal *temporal)
77
temporal->set_hours(0);
78
temporal->set_minutes(0);
79
temporal->set_seconds(0);
80
temporal->set_epoch_seconds();
83
void TemporalGenerator::TemporalGen::make_max_time(drizzled::Temporal *temporal)
85
temporal->set_hours(23);
86
temporal->set_minutes(59);
87
temporal->set_seconds(59);
88
temporal->set_epoch_seconds();
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)
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();
105
void TemporalGenerator::DateTimeGen::make_valid_datetime(drizzled::DateTime *datetime)
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();
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)
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();
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)
134
make_timestamp(timestamp, years, months, days, hours, minutes, seconds);
135
timestamp->set_useconds(microseconds);
136
timestamp->set_epoch_seconds();
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)
144
make_timestamp(timestamp, years, months, days, hours, minutes, seconds);
145
timestamp->set_nseconds(nanoseconds);
146
timestamp->set_epoch_seconds();
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)
159
drizzled::TemporalFormat *temporal_format= new drizzled::TemporalFormat(regexp);
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);
170
return temporal_format;
173
drizzled::TemporalInterval *TemporalGenerator::TemporalIntervalGen::make_temporal_interval(
180
uint64_t second_part,
183
drizzled::TemporalInterval *interval= new drizzled::TemporalInterval();
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);