1
0
Fork 0
mirror of https://github.com/IRS-Public/direct-file.git synced 2025-06-27 20:25:52 +00:00

fix isTaxYearLeapYear

This commit is contained in:
Elijah Wright 2025-05-30 01:57:26 -07:00
parent e0d5c84451
commit 9739d20233
2 changed files with 85 additions and 12 deletions

View file

@ -50,24 +50,62 @@
<!-- TODO: replace this with the calc to determine leap year (e.g. divisible by 4, but not 100 unless also divisible by 400) -->
<Case>
<When>
<Any>
<Equal>
<Left>
<Modulo>
<Left>
<Dependency path="/taxYear" />
</Left>
<Right>
<Int>100</Int>
</Right>
</Modulo>
</Left>
<Right>
<Int>0</Int>
</Right>
</Equal>
</When>
<Then>
<When>
<Equal>
<Left>
<Dependency path="/taxYear" />
<Modulo>
<Left>
<Dependency path="/taxYear" />
</Left>
<Right>
<Int>400</Int>
</Right>
</Modulo>
</Left>
<Right>
<Int>2024</Int>
<Int>0</Int>
</Right>
</Equal>
<Equal>
<Left>
<Dependency path="/taxYear" />
</Left>
<Right>
<Int>2028</Int>
</Right>
</Equal>
</Any>
</When>
<Then>
<True />
</When>
</Then>
</Case>
<Case>
<When>
<Equal>
<Left>
<Modulo>
<Left>
<Dependency path="/taxYear" />
</Left>
<Right>
<Int>4</Int>
</Right>
</Modulo>
</Left>
<Right>
<Int>0</Int>
</Right>
</Equal>
</When>
<Then>
<True />

View file

@ -0,0 +1,35 @@
package gov.irs.factgraph.compnodes
import gov.irs.factgraph.{Expression, FactDictionary, Factual}
import gov.irs.factgraph.definitions.fact.CompNodeConfigTrait
import gov.irs.factgraph.operators.BinaryOperator
object Modulo extends CompNodeFactory:
override val Key: String = "Modulo"
private val operator = ModuloOperator()
def apply(lhs: CompNode, rhs: CompNode): BooleanNode =
if (lhs.getClass != rhs.getClass)
throw new UnsupportedOperationException(
s"cannot modulate a ${lhs.getClass.getName} and a ${rhs.getClass.getName}",
)
BooleanNode(
Expression.Binary(
lhs.expr,
rhs.expr,
operator,
),
)
override def fromDerivedConfig(e: CompNodeConfigTrait)(using Factual)(using
FactDictionary,
): CompNode =
val lhs = CompNode.getConfigChildNode(e, "Left")
val rhs = CompNode.getConfigChildNode(e, "Right")
this(lhs, rhs)
private final class ModuloOperator extends BinaryOperator[Boolean, Any, Any]:
override protected def operation(x: Any, y: Any): Boolean = x % y