# Implementation Tasks: rhai-timestamp

**Branch**: `045-rhai-timestamp`
**Date**: 2026-06-18
**Spec**: `/specs/045-rhai-timestamp/spec.md`

## Phase 1: Setup

*No setup tasks required. The Rhai engine already natively supports this without feature flags or new dependencies.*

## Phase 2: Foundational

*No foundational tasks required.*

## Phase 3: User Story 1 - Rhai Script with Time (Priority: P1)

**Goal**: Ensure users can measure execution time or block execution using standard time concepts (`timestamp()`, `elapsed()`, and `sleep()`) inside their Rhai scripts, AND pass/return `Value::Timestamp` to/from scripts.

**Independent Test**: Can be tested via `cargo nextest run --test rhai_scripting_test --features rhai`.

**Tasks**:

- [x] T001 [US1] Create a custom `RhaiDateTime` proxy object in `src/functions/backends/rhai.rs` to represent `Value::Timestamp`
- [x] T002 [US1] Update `value_to_dynamic` in `src/functions/backends/rhai.rs` to map `Value::Timestamp` to `RhaiDateTime`
- [x] T003 [US1] Update `dynamic_to_value` in `src/functions/backends/rhai.rs` to map `RhaiDateTime` back to `Value::Timestamp`
- [x] T004 [US1] Create explicit timestamp test cases in `tests/rhai_scripting_test.rs` to verify `timestamp()` and passing/returning DateTime objects

## Phase 4: Polish & Cross-Cutting

- [x] T002 Update Rhai scripting documentation in `docs/_docs/tutorials/procedures/rhai.md` to mention time functions support
- [x] T003 Verify the code with `make lint` and tests with `make test`

## Dependencies

- None.

## Parallel Execution Opportunities

- T001 and T002 can be done in parallel.

## Implementation Strategy

1. Add comprehensive integration tests in `tests/rhai_scripting_test.rs` to prove that `timestamp()` and `sleep()` are natively exposed by the existing Rhai engine integration.
2. Update the user documentation to make it clear to end users that time manipulation is fully supported in Rhai stored procedures.