Skip to content

Implement DateNodeBehavior #131

Closed
Closed

Description

@malibio

Overview

Implement the DateNodeBehavior for handling date nodes with deterministic IDs and date validation.

Prerequisites

Before starting this issue:

Implementation Tasks

  • Create DateNodeBehavior struct implementing NodeBehavior trait
  • Implement date format validation using regex (YYYY-MM-DD)
  • Add date validity check using chrono::NaiveDate
  • Implement create_date_node helper for deterministic date node creation
  • Validate that content matches ID
  • Set default metadata for date nodes
  • Implement deletion behavior (orphan children)
  • Add comprehensive unit tests for date validation and creation

Acceptance Criteria

  • DateNodeBehavior properly implements all NodeBehavior trait methods
  • Date validation uses regex pattern ^\d{4}-\d{2}-\d{2}$
  • Invalid dates (e.g., 2024-13-45) are rejected using chrono validation
  • Node ID matches content exactly (both are YYYY-MM-DD)
  • create_date_node helper creates valid date nodes with deterministic IDs
  • Default metadata includes timezone and is_holiday fields
  • Deletion behavior orphans children (doesn't cascade delete)
  • Unit tests cover valid dates, invalid formats, and edge cases
  • Code follows Rust best practices and passes cargo clippy

Technical Specifications

Implementation Pattern:

pub struct DateNodeBehavior;

impl NodeBehavior for DateNodeBehavior {
    fn type_name(&self) -> &'static str {
        "date"
    }

    fn validate(&self, node: &Node) -> Result<(), ValidationError> {
        // Validate YYYY-MM-DD format using regex
        // Validate actual date validity using chrono
        // Ensure content matches ID
    }

    fn can_have_children(&self) -> bool {
        true // Dates can contain events, tasks, etc.
    }

    fn supports_markdown(&self) -> bool {
        false // Dates are simple identifiers
    }

    fn default_metadata(&self) -> Value {
        json!({
            "is_holiday": false,
            "timezone": "UTC"
        })
    }
}

impl DateNodeBehavior {
    pub fn create_date_node(date: &str) -> Result<Node, ProcessingError> {
        // Validate and create date node with deterministic ID
    }
}

Date Node Design:

  • ID format: YYYY-MM-DD (e.g., 2024-01-15) - NO date: prefix
  • Content: Matches ID exactly
  • Deterministic: Same date always produces same node ID
  • No embeddings: embedding_vector is always None
  • No complementary table: Uses only universal nodes table

Validation Requirements:

  • Regex: ^\d{4}-\d{2}-\d{2}$ (format check)
  • Chrono: NaiveDate::parse_from_str (validity check)
  • Content == ID (consistency check)

Dependencies:

Testing Requirements:

  • Test valid dates: 2024-01-15, 2025-12-31
  • Test invalid formats: 24-1-15, 2024/01/15, date:2024-01-15
  • Test invalid dates: 2024-13-01, 2024-02-30, 2024-00-15
  • Test create_date_node helper
  • Test content/ID mismatch rejection
  • Test default metadata generation

Related Issues

Implementation Notes

  • No date: prefix: Unlike early designs, use clean YYYY-MM-DD format
  • No recurring field: Recurrence belongs to future RecurringEventNode type
  • No complementary table: Date nodes use only the universal nodes table
  • Embeddings: Always None - dates don't need semantic search
  • Lazy static: Use lazy_static crate for regex pattern compilation

This provides the foundation for date-based organization in NodeSpace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions