1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-04-20 09:07:44 +03:00
Leonid Fedorov 3919c541ac
New warnfixes (#2254)
* Fix clang warnings

* Remove vim tab guides

* initialize variables

* 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length

* Fix ISO C++17 does not allow 'register' storage class specifier for outdated bison

* chars are unsigned on ARM, having  if (ival < 0) always false

* chars are unsigned by default on ARM and comparison with -1 if always true
2022-02-17 13:08:58 +03:00

97 lines
2.4 KiB
C++

/* Copyright (C) 2014 InfiniDB, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
/****************************************************************************
* $Id: func_period_add.cpp 2477 2011-04-01 16:07:35Z rdempsey $
*
*
****************************************************************************/
#include <cstdlib>
#include <string>
#include <sstream>
using namespace std;
#include "functor_int.h"
#include "funchelpers.h"
#include "functioncolumn.h"
#include "rowgroup.h"
using namespace execplan;
#include "dataconvert.h"
namespace funcexp
{
CalpontSystemCatalog::ColType Func_period_add::operationType(FunctionParm& fp,
CalpontSystemCatalog::ColType& resultType)
{
return resultType;
}
int64_t Func_period_add::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
int64_t period = parm[0]->data()->getIntVal(row, isNull);
if (period < 10000)
{
// get first 2 digits of year
time_t now;
now = time(NULL);
struct tm tm;
localtime_r(&now, &tm);
char timestamp[10];
strftime(timestamp, 10, "%Y", &tm);
string Syear = timestamp;
Syear = Syear.substr(0, 2);
int topyear = atoi(Syear.c_str());
period = (topyear * 10000) + period;
}
int64_t year = period / 100;
int64_t month = period - (year * 100);
int64_t months = parm[1]->data()->getIntVal(row, isNull);
int64_t yearsAdd = months / 12;
int64_t monthsAdd = months - (yearsAdd * 12);
year = year + yearsAdd;
month = month + monthsAdd;
if (month > 12)
{
year++;
month = month - 12;
}
else
{
if (month < 1)
{
year--;
month = month + 12;
}
}
int64_t value = (year * 100) + month;
return value;
}
} // namespace funcexp