MD.OFFICE
FAL

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)

  1. Parser Augmentation: Overrode expr-eval binary operators + and - to natively handle Date objects at runtime.
  2. Type Safety Bypass: Bypassed strict typings from expr.evaluate via type casting to process our custom Date instances successfully.
  3. Payload Hydration: Intercepted the inbound HTTP JSON requests to parse and revive strict ISO 8601 string-serialized dates back into JavaScript Date instances before parser evaluation. Renamed reviveValues to hydrateDateValues for semantic correctness.
  4. DST-Safe Arithmetic: Implemented addDaysToDate helper logic that deliberately computes using date.getTime() + (days * 86400000) absolute UTC milliseconds rather than setDate(). This prevents edge cases such as Fractional days rolling over incorrectly or "missing/duplicate hours" during Daylight Saving Time zone shifts.
  5. Endpoint Optimization: Removed the redundant evaluation methods from the /validate parser check to improve semantic purity.

Frontend Formulas and Rendering

  1. Validation Safeguards: Upgraded formula-builder.component.ts to strictly detect identical or multiple date variables and prevent mathematically impossible additions (e.g., @Date1 + @Date2) by tracing label-based regex occurrences.
  2. 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, and outputType: 'decimal' when Dates are subtracted against Dates).
  3. Field Hydration: Upgraded formula-field.component.ts to natively interpret the result payload, leveraging a shared reviveDateString utility to parse API responses, and structurally evaluating config.outputType to switch the DOM conditionally to a p-datepicker.
  4. 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.
  5. Type Mismatch Guarding: Upgraded formula-rule-evaluator.util.ts to intercept evaluateComparison, verifying type equality before arithmetic to defensively prevent Date > 100 numeric crashes.

Documentation

  • Updated dynaforms-history.md outlining the core decisions, fallback designs, and solutions of the code review refactoring session.
  • Drafted a full-architecture feature guide in date-formula-support.md mapping out logic routes via Mermaid flowcharting and extensively explaining timezone choices.