Daily Log: 2026-03-12
Date Formula Feature Implementation
Today's primary focus was completing the full-stack implementation of the Date Formula Support feature in Dynaforms, allowing dynamic calculations such as Start Date + 30 Days and End Date - Start Date.
Backend Enhancements (formula.controller.ts)
- Parser Augmentation: Overrode
expr-evalbinary operators+and-to natively handleDateobjects at runtime. - Type Safety Bypass: Bypassed strict typings from
expr.evaluatevia type casting to process our custom Date instances successfully. - Payload Hydration: Intercepted the inbound HTTP JSON requests to parse and revive strict ISO 8601 string-serialized dates back into JavaScript
Dateinstances before parser evaluation. RenamedreviveValuestohydrateDateValuesfor semantic correctness. - DST-Safe Arithmetic: Implemented
addDaysToDatehelper logic that deliberately computes usingdate.getTime() + (days * 86400000)absolute UTC milliseconds rather thansetDate(). This prevents edge cases such as Fractional days rolling over incorrectly or "missing/duplicate hours" during Daylight Saving Time zone shifts. - Endpoint Optimization: Removed the redundant evaluation methods from the
/validateparser check to improve semantic purity.
Frontend Formulas and Rendering
- Validation Safeguards: Upgraded
formula-builder.component.tsto strictly detect identical or multiple date variables and prevent mathematically impossible additions (e.g.,@Date1 + @Date2) by tracing label-based regex occurrences. - Implicit Component Return Types: Programmed the builder heuristic to automatically label the output state correctly (emitting
outputType: 'date'when Dates are added/subtracted with Numbers, andoutputType: 'decimal'when Dates are subtracted against Dates). - Field Hydration: Upgraded
formula-field.component.tsto natively interpret the result payload, leveraging a sharedreviveDateStringutility to parse API responses, and structurally evaluatingconfig.outputTypeto switch the DOM conditionally to ap-datepicker. - Strict Equality Loop Fix: Shifted the frontend state comparison check to explicitly verify absolute integer
getTime() === getTime()over loose object reference===variables, eliminating infinite rendering loops. - Type Mismatch Guarding: Upgraded
formula-rule-evaluator.util.tsto interceptevaluateComparison, verifying type equality before arithmetic to defensively preventDate > 100numeric crashes.
Documentation
- Updated
dynaforms-history.mdoutlining the core decisions, fallback designs, and solutions of the code review refactoring session. - Drafted a full-architecture feature guide in
date-formula-support.mdmapping out logic routes via Mermaid flowcharting and extensively explaining timezone choices.