Skip to content

Commit

Permalink
So much work on DatePart
Browse files Browse the repository at this point in the history
  • Loading branch information
James Dunkerley committed Feb 27, 2019
1 parent 0926055 commit e114270
Show file tree
Hide file tree
Showing 15 changed files with 1,296 additions and 25,545 deletions.
Binary file modified AlteryxAbacus.dll
Binary file not shown.
281 changes: 216 additions & 65 deletions DateUtils.Test/DatePartTest.yxmd

Large diffs are not rendered by default.

Binary file modified DateUtils.Test/DateReference.xlsx
Binary file not shown.
Binary file modified DateUtils.Test/DateTimeReference.xlsx
Binary file not shown.
358 changes: 358 additions & 0 deletions DateUtils.Test/WeekNumTest.yxmd

Large diffs are not rendered by default.

32 changes: 28 additions & 4 deletions DateUtils.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
<Description>Extracts Time from a DateTime or Date</Description>
<Formula>IIF(LENGTH(P1) = 19, RIGHT(P1,8), IIF(LENGTH(P1) = 10, '00:00:00', IIF(LENGTH(P1) = 8, P1, NULL())))</Formula>
</Function>

<Function>
<Name>DATEADD</Name>
<NumParams variable="false">3</NumParams>
Expand All @@ -153,7 +152,6 @@
<Description>Add a specific interval to a date/time and returns as a Date. DateAdd([Date], -3, "days")</Description>
<Formula>Left(DateTimeAdd(P1, P2, P3), 10)</Formula>
</Function>

<Function>
<Name>BUSINESSDAYS</Name>
<NumParams variable="false">2</NumParams>
Expand All @@ -162,7 +160,14 @@
<Description>Number of business days (M-F) between two dates.</Description>
<Formula>IIF(P1>P2,NULL(), 1 + ((DateTimeDiff(P2,P1,"days")*5 - (WEEKDAY(P1)-WEEKDAY(P2))*2) / 7) + IIF(WEEKDAY(P2)==6,-1,0) + IIF(WEEKDAY(P1)==0,-1,0))</Formula>
</Function>

<Function>
<Name>WEEKNUM</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>WeekNum(dt)</InsertText>
<Description>Move to First day of the week (Sunday)</Description>
<Formula>CEIL((DateTimeDiff(P1, WEEKSTART(LEFT(P1,4) + "-01-01"), "days") + 1) / 7)</Formula>
</Function>
<Function>
<Name>WEEKSTART</Name>
<NumParams variable="false">1</NumParams>
Expand Down Expand Up @@ -249,6 +254,25 @@
<Category>DateTime</Category>
<InsertText>DATEPART(interval, dt)</InsertText>
<Description>Reproduces SQL Server's DatePart function. Support SQL servers standard parts as well as the numeric Alteryx date formatters.</Description>
<Formula>Switch(LOWERCASE(P1),NULL(),"year",Year(P2),"yyyy",Year(P2),"yy",Year(P2),"%y",Year(P2),"century",Century(P2),"cc",Century(P2),"c",Century(P2),"%c",Century(P2),"quarter",Quarter(P2),"qq",Quarter(P2),"q",Quarter(P2),"month",Month(P2),"mm",Month(P2),"m",Month(P2),"dayofyear",OrdinalDay(P2),"dy",OrdinalDay(P2),"y",OrdinalDay(P2),"%j",OrdinalDay(P2),"day",DAY(P2),"dd",DAY(P2),"d",DAY(P2),"%d",DAY(P2),"%e",DAY(P2),"hour",HOUR(P2),"hh",HOUR(P2),"h",HOUR(P2),"%h",HOUR(P2),"%k",HOUR(P2),"mi",MINUTE(P2),"n",MINUTE(P2),"ss",SECOND(P2),"s",SECOND(P2),"%s",SECOND(P2),"%m",IIF(CharToInt(Right(P1,1))=77, MINUTE(P2),MONTH(P2)),"weekday",WEEKDAY(P2),"dw",WEEKDAY(P2))</Formula>
<Formula>IF LOWERCASE(P1) IN ("century", "cc", "c") THEN Century(P2)
ELSEIF P1 = "%C" THEN Century(P2)-1
ELSEIF P1 = "%y" AND CHARTOINT(RIGHT(P1,1))=121 THEN MOD(YEAR(P2),100)
ELSEIF LOWERCASE(P1) IN ("year", "yyyy", "yy", "%y") THEN Year(P2)
ELSEIF LOWERCASE(P1) IN ("quarter","qq","q") THEN Quarter(P2)
ELSEIF LOWERCASE(P1) IN ("month","mm","m") THEN Month(P2)
ELSEIF P1 = "%m" AND CHARTOINT(RIGHT(P1,1))=109 THEN MONTH(P2)
ELSEIF LOWERCASE(P1) IN ("dayofyear","dy","y","%j") THEN OrdinalDay(P2)
ELSEIF LOWERCASE(P1) IN ("day","dd","d","%d","%e") THEN Day(P2)
ELSEIF LOWERCASE(P1) IN ("weekday","dw","w") THEN Weekday(P2)
ELSEIF P1 = "%w" AND CHARTOINT(RIGHT(P1,1))=119 THEN Weekday(P2)
ELSEIF P1 = "%u" AND CHARTOINT(RIGHT(P1,1))=117 THEN IIF(Weekday(P2)=0,7,Weekday(P2))
ELSEIF LOWERCASE(P1) IN ("week","ww","wk") THEN Weeknum(P2)
ELSEIF LOWERCASE(P1) IN ("%u") THEN Weeknum(P2)-IIF(Weekday(YearStart(P2))=0,0,1)
ELSEIF LOWERCASE(P1) IN ("%w") THEN TONUMBER(DATETIMEFORMAT(P2,"%W"))
ELSEIF LOWERCASE(P1) IN ("hour","hh","h","%h","%k") THEN Hour(P2)
ELSEIF LOWERCASE(P1) IN ("%i","%l") THEN IIF(MOD(Hour(P2),12)=0, 12, MOD(Hour(P2),12))
ELSEIF LOWERCASE(P1) IN ("minute","mi","n","%m") THEN Minute(P2)
ELSEIF LOWERCASE(P1) IN ("second","ss","s","%s") THEN Second(P2)
ELSE NULL() ENDIF</Formula>
</Function>
</FormulaAddIn>
Binary file added MathUtils.Test/DivisionTests.xlsx
Binary file not shown.
178 changes: 178 additions & 0 deletions MathUtils.Test/IntTest.yxmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?xml version="1.0"?>
<AlteryxDocument yxmdVer="2018.4">
<Nodes>
<Node ToolID="2">
<GuiSettings Plugin="AlteryxBasePluginsGui.Formula.Formula">
<Position x="162" y="54" />
</GuiSettings>
<Properties>
<Configuration>
<FormulaFields>
<FormulaField expression="INT([Number])" field="Actual" size="8" type="Double" />
</FormulaFields>
</Configuration>
<Annotation DisplayMode="0">
<Name />
<DefaultAnnotationText><![CDATA[Actual = INT([Number])
]]></DefaultAnnotationText>
<Left value="False" />
</Annotation>
</Properties>
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxFormula" />
</Node>
<Node ToolID="3">
<GuiSettings Plugin="AlteryxBasePluginsGui.Filter.Filter">
<Position x="282" y="54" />
</GuiSettings>
<Properties>
<Configuration>
<Expression>ABS([Actual] - [Expected]) &gt; 1e-6</Expression>
<Mode>Custom</Mode>
</Configuration>
<Annotation DisplayMode="0">
<Name />
<DefaultAnnotationText>ABS([Actual] - [Expected]) &gt; 1e-6</DefaultAnnotationText>
<Left value="False" />
</Annotation>
</Properties>
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxFilter" />
</Node>
<Node ToolID="4">
<GuiSettings Plugin="AlteryxBasePluginsGui.Test.Test">
<Position x="402" y="54" />
</GuiSettings>
<Properties>
<Configuration>
<Tests>
<Test>
<Name>Int</Name>
<Connection>#1</Connection>
<Type>RecCountValue</Type>
<Value>0</Value>
</Test>
</Tests>
<DontReportSubsequent value="True" />
</Configuration>
<Annotation DisplayMode="0">
<Name />
<DefaultAnnotationText>Int</DefaultAnnotationText>
<Left value="False" />
</Annotation>
</Properties>
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxTest" />
</Node>
<Node ToolID="5">
<GuiSettings Plugin="AlteryxBasePluginsGui.DbFileInput.DbFileInput">
<Position x="18" y="54" />
</GuiSettings>
<Properties>
<Configuration>
<Passwords />
<File OutputFileName="" RecordLimit="" SearchSubDirs="False" FileFormat="25">.\DivisionTests.xlsx|||`Sheet1$`</File>
<FormatSpecificOptions>
<FirstRowData>False</FirstRowData>
<ImportLine>1</ImportLine>
</FormatSpecificOptions>
</Configuration>
<Annotation DisplayMode="0">
<Name />
<DefaultAnnotationText>DivisionTests.xlsx
Table=`Sheet1$`</DefaultAnnotationText>
<Left value="False" />
</Annotation>
<Dependencies>
<Implicit />
</Dependencies>
<MetaInfo connection="Output">
<RecordInfo>
<Field name="Numerator" source="File: C:\Repos\AlteryxFormulaAddOns\MathUtils.Test\DivisionTests.xlsx|||`Sheet1$`" type="Double" />
<Field name="Denominator" source="File: C:\Repos\AlteryxFormulaAddOns\MathUtils.Test\DivisionTests.xlsx|||`Sheet1$`" type="Double" />
<Field name="SIGN" source="File: C:\Repos\AlteryxFormulaAddOns\MathUtils.Test\DivisionTests.xlsx|||`Sheet1$`" type="Double" />
<Field name="MODULO" source="File: C:\Repos\AlteryxFormulaAddOns\MathUtils.Test\DivisionTests.xlsx|||`Sheet1$`" type="Double" />
<Field name="QUOTIENT" source="File: C:\Repos\AlteryxFormulaAddOns\MathUtils.Test\DivisionTests.xlsx|||`Sheet1$`" type="Double" />
<Field name="INT" source="File: C:\Repos\AlteryxFormulaAddOns\MathUtils.Test\DivisionTests.xlsx|||`Sheet1$`" type="Double" />
</RecordInfo>
</MetaInfo>
</Properties>
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxDbFileInput" />
</Node>
<Node ToolID="6">
<GuiSettings Plugin="AlteryxBasePluginsGui.AlteryxSelect.AlteryxSelect">
<Position x="90" y="54" />
</GuiSettings>
<Properties>
<Configuration>
<OrderChanged value="False" />
<CommaDecimal value="False" />
<SelectFields>
<SelectField field="Numerator" selected="True" rename="Number" />
<SelectField field="INT" selected="True" rename="Expected" />
<SelectField field="*Unknown" selected="False" />
</SelectFields>
</Configuration>
<Annotation DisplayMode="0">
<Name />
<DefaultAnnotationText />
<Left value="False" />
</Annotation>
</Properties>
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxSelect" />
</Node>
</Nodes>
<Connections>
<Connection>
<Origin ToolID="2" Connection="Output" />
<Destination ToolID="3" Connection="Input" />
</Connection>
<Connection name="#1">
<Origin ToolID="3" Connection="True" />
<Destination ToolID="4" Connection="Input" />
</Connection>
<Connection>
<Origin ToolID="5" Connection="Output" />
<Destination ToolID="6" Connection="Input" />
</Connection>
<Connection>
<Origin ToolID="6" Connection="Output" />
<Destination ToolID="2" Connection="Input" />
</Connection>
</Connections>
<Properties>
<Memory default="True" />
<GlobalRecordLimit value="0" />
<TempFiles default="True" />
<Annotation on="True" includeToolName="False" />
<ConvErrorLimit value="10" />
<ConvErrorLimit_Stop value="False" />
<CancelOnError value="False" />
<DisableBrowse value="False" />
<EnablePerformanceProfiling value="False" />
<DisableAllOutput value="False" />
<ShowAllMacroMessages value="False" />
<ShowConnectionStatusIsOn value="True" />
<ShowConnectionStatusOnlyWhenRunning value="True" />
<ZoomLevel value="0" />
<LayoutType>Horizontal</LayoutType>
<MetaInfo>
<NameIsFileName value="True" />
<Name>IntTest</Name>
<Description />
<RootToolName />
<ToolVersion />
<ToolInDb value="False" />
<CategoryName />
<SearchTags />
<Author />
<Company />
<Copyright />
<DescriptionLink actual="" displayed="" />
<Example>
<Description />
<File />
</Example>
</MetaInfo>
<Events>
<Enabled value="True" />
</Events>
</Properties>
</AlteryxDocument>
Loading

0 comments on commit e114270

Please sign in to comment.