Skip to content

Commit

Permalink
v1.4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
James Dunkerley committed Nov 19, 2018
1 parent b2b5efd commit e0745cc
Show file tree
Hide file tree
Showing 11 changed files with 1,072 additions and 66 deletions.
Binary file modified AlteryxAbacus.dll
Binary file not shown.
Binary file modified AlteryxAbacus/AlteryxAbacus.aps
Binary file not shown.
38 changes: 38 additions & 0 deletions AlteryxAbacus/AlteryxAbacus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,43 @@ extern "C" long _declspec(dllexport) _stdcall Split(int nNumArgs, FormulaAddInDa
pReturnValue->isNull = 0;
}

return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

// Need String, String (char), Integer
extern "C" long _declspec(dllexport) _stdcall RangeJoin(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
pReturnValue->nVarType = 1;

// Check Input Parameters
if (nNumArgs != 2 ||
pArgs[0].nVarType != 1 ||
pArgs[1].nVarType != 2) {
return AlteryxAbacusUtils::ReturnError(L"Syntax: Number, RangeList", pReturnValue, nNumArgs, pArgs);
}

// Check for Nulls
if (pArgs[0].isNull || pArgs[2].isNull) {
pReturnValue->isNull = 1;
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

// Read Target Value to Long Long
const auto target = static_cast<long long>(pArgs[0].dVal);

// Read String
const wchar_t* start = pArgs[1].pVal - 1;
while (*start != L'\0') {
wchar_t* end;
const auto value = _wcstoi64(start + 1, &end, 10);
start = end;
if (value > target)
{
pReturnValue->dVal = value;
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}
}

pReturnValue->isNull = 1;
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}
Binary file modified AlteryxAbacus/AlteryxAbacus.rc
Binary file not shown.
59 changes: 37 additions & 22 deletions AlteryxAbacus/DateTimeFunctions.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <string>
#include "AlteryxAbacus.h"
#include "AlteryxAbacusUtils.h"
#include <windows.h>

const int daysInMonthArray[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int daysInMonth(int year, int month)
int days_in_month(int year, int month)
{
if (month < 1 || month > 12)
{
Expand All @@ -28,9 +29,9 @@ extern "C" long __declspec(dllexport) _stdcall MakeDate(int nNumArgs, FormulaAdd
return AlteryxAbacusUtils::ReturnError(L"MakeDate: Requires between 1 and 3 numerical arguments", pReturnValue, nNumArgs, pArgs);
}

int year = static_cast<int>(pArgs[0].dVal);
int month = nNumArgs > 1 && !pArgs[1].isNull ? static_cast<int>(pArgs[1].dVal) : 1;
int day = nNumArgs > 2 && !pArgs[2].isNull ? static_cast<int>(pArgs[2].dVal) : 1;
const auto year = static_cast<int>(pArgs[0].dVal);
const auto month = nNumArgs > 1 && !pArgs[1].isNull ? static_cast<int>(pArgs[1].dVal) : 1;
const auto day = nNumArgs > 2 && !pArgs[2].isNull ? static_cast<int>(pArgs[2].dVal) : 1;

if (year == 0 && month == 0 && day == 0)
{
Expand All @@ -49,17 +50,24 @@ extern "C" long __declspec(dllexport) _stdcall MakeDate(int nNumArgs, FormulaAdd
return AlteryxAbacusUtils::ReturnError(L"MakeDate: Month must be between 1 and 12", pReturnValue, nNumArgs, pArgs);
}

int maxDay = daysInMonth(year, month);
if (day < 1 || day > maxDay)
{
std::wstring msg(L"MakeDate: Day must be between 1 and ");
return AlteryxAbacusUtils::ReturnError((msg + std::to_wstring(maxDay)).c_str(), pReturnValue, nNumArgs, pArgs);
if (day > 28 || day < 1) {
const int max_day = days_in_month(year, month);
if (day < 1 || day > max_day)
{
const std::wstring msg(L"MakeDate: Day must be between 1 and ");
return AlteryxAbacusUtils::ReturnError((msg + std::to_wstring(max_day)).c_str(), pReturnValue, nNumArgs, pArgs);
}
}

std::wstring output = std::to_wstring(year);
output += (month < 10 ? L"-0" : L"-") + std::to_wstring(month);
output += (day < 10 ? L"-0" : L"-") + std::to_wstring(day);
AlteryxAbacusUtils::SetString(pReturnValue, output.c_str());
const long long dt = year * 1000000LL + month * 1000L + day;
//std::wstring output = std::to_wstring(dt);
//AlteryxAbacusUtils::SetString(pReturnValue, output.c_str());
auto *p_string_ret = static_cast<wchar_t *>(GlobalAlloc(GMEM_FIXED, 11 * sizeof(wchar_t)));
_i64tow_s(dt, p_string_ret, 11 * sizeof(wchar_t), 10);
p_string_ret[4] = L'-';
p_string_ret[7] = L'-';
p_string_ret[10] = L'\0';
pReturnValue->pVal = p_string_ret;
pReturnValue->isNull = 0;
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}
Expand All @@ -73,9 +81,9 @@ extern "C" long __declspec(dllexport) _stdcall MakeTime(int nNumArgs, FormulaAdd
return AlteryxAbacusUtils::ReturnError(L"MakeTime: Requires between 0 and 3 numerical arguments", pReturnValue, nNumArgs, pArgs);
}

int hour = nNumArgs > 0 && !pArgs[0].isNull ? static_cast<int>(pArgs[0].dVal) : 0;
int minute = nNumArgs > 1 && !pArgs[1].isNull ? static_cast<int>(pArgs[1].dVal) : 0;
int second = nNumArgs > 2 && !pArgs[2].isNull ? static_cast<int>(pArgs[2].dVal) : 0;
const auto hour = nNumArgs > 0 && !pArgs[0].isNull ? static_cast<int>(pArgs[0].dVal) : 0;
const auto minute = nNumArgs > 1 && !pArgs[1].isNull ? static_cast<int>(pArgs[1].dVal) : 0;
const auto second = nNumArgs > 2 && !pArgs[2].isNull ? static_cast<int>(pArgs[2].dVal) : 0;

if (hour < 0 || hour > 23)
{
Expand All @@ -92,18 +100,25 @@ extern "C" long __declspec(dllexport) _stdcall MakeTime(int nNumArgs, FormulaAdd
return AlteryxAbacusUtils::ReturnError(L"MakeTime: Second must be between 0 and 59", pReturnValue, nNumArgs, pArgs);
}

std::wstring output = (hour < 10 ? L"0" : L"") + std::to_wstring(hour);
output += (minute < 10 ? L":0" : L":") + std::to_wstring(minute);
output += (second < 10 ? L":0" : L":") + std::to_wstring(second);
AlteryxAbacusUtils::SetString(pReturnValue, output.c_str());
auto *p_string_ret = static_cast<wchar_t *>(GlobalAlloc(GMEM_FIXED, 9 * sizeof(wchar_t)));
_itow_s((hour+30) * 10000 + minute * 100 + second, p_string_ret, 8 * sizeof(wchar_t), 10);
*(p_string_ret + 8) = L'\0';
*(p_string_ret + 7) = *(p_string_ret + 5);
*(p_string_ret + 6) = *(p_string_ret + 4);
*(p_string_ret + 5) = L':';
*(p_string_ret + 4) = *(p_string_ret + 3);
*(p_string_ret + 3) = *(p_string_ret + 2);
*(p_string_ret + 2) = L':';
*p_string_ret = *p_string_ret - 3;
pReturnValue->pVal = p_string_ret;
pReturnValue->isNull = 0;
return AlteryxAbacusUtils::ReturnSuccess(nNumArgs, pArgs);
}

extern "C" long __declspec(dllexport) _stdcall MakeDateTime(int nNumArgs, FormulaAddInData *pArgs, FormulaAddInData *pReturnValue)
{
// The Date Part
long dateResult = MakeDate(nNumArgs > 3 ? 3 : nNumArgs, pArgs, pReturnValue);
const long dateResult = MakeDate(nNumArgs > 3 ? 3 : nNumArgs, pArgs, pReturnValue);
if (dateResult != 0)
{
std::wstring msg(pReturnValue->pVal);
Expand All @@ -123,7 +138,7 @@ extern "C" long __declspec(dllexport) _stdcall MakeDateTime(int nNumArgs, Formul
}

// The Time Part
long timeResult = MakeTime(nNumArgs - 3, pArgs + 3, pReturnValue);
const long timeResult = MakeTime(nNumArgs - 3, pArgs + 3, pReturnValue);
if (timeResult != 0)
{
std::wstring msg(pReturnValue->pVal);
Expand Down
Loading

0 comments on commit e0745cc

Please sign in to comment.