# timestamp-unification

## AUDIT (2026-02-06)

Pattern: Multiple implementations of `current_timestamp()` and inline `SystemTime::now()` / `Utc::now().timestamp()` calls.

Found: 11 instances in 6 files (production code)
- 2 duplicate function definitions
- 4 inline implementations
- 5 test-only usages (acceptable)

### Decision

1. Keep `episteme/corpus.rs:current_timestamp()` as canonical, make it `pub`
2. Export from `lib.rs` for easy access
3. Remove duplicate in `research/gap_store.rs`
4. Replace inline implementations with function call
5. Keep `scan/scanner.rs` millis variant separate (different unit)
6. Keep test code as-is (test isolation is acceptable)

## FIX LOG

- [x] episteme/corpus.rs:15 - Made `current_timestamp()` public, added comprehensive docstring, added `current_timestamp_millis()` variant
- [x] episteme/mod.rs - Re-exported `current_timestamp` and `current_timestamp_millis`
- [x] lib.rs - Added `pub use episteme::{current_timestamp, current_timestamp_millis}`
- [x] research/gap_store.rs:297 - Removed duplicate `fn current_timestamp()`, now imports from `crate::current_timestamp`
- [x] corpus_build.rs:63 - Replaced inline `SystemTime::now()` with `current_timestamp()`
- [x] policy.rs:128 - Replaced inline `SystemTime::now()` with `current_timestamp()`
- [x] policy.rs:236 - Replaced inline `SystemTime::now()` with `current_timestamp()`
- [x] expiry.rs:102 - Replaced `Utc::now().timestamp()` with `current_timestamp()`
- [x] scan/scanner.rs:267 - Replaced inline millis with `current_timestamp_millis()`

## VERIFY (2026-02-06)

```bash
cargo test -p aphoria  # 782 passed
cargo clippy -p aphoria -- -D warnings  # No warnings
```

Remaining instances (all acceptable):
- `episteme/corpus.rs:21,28` - CANONICAL IMPLEMENTATION
- `expiry.rs:132,153,212,219` - Test code in `#[cfg(test)]` module
- `tests/ack_expiry.rs` - Test file

## ENFORCE (2026-02-06)

Updated `.claude/skills/aphoria-dev/skill.md`:

1. Added "Do Not #11": "Write inline timestamp code. Use `crate::current_timestamp()` or `crate::current_timestamp_millis()`"

2. Added to Constraints/NEVER: "Write inline timestamp code (use `current_timestamp()` from crate root)"

3. Added to Constraints/ALWAYS:
   - "Use `crate::current_timestamp()` for Unix timestamps in seconds"
   - "Use `crate::current_timestamp_millis()` for millisecond precision"

## DOCUMENT (2026-02-06)

Canonical implementation documented in `episteme/corpus.rs:15-28`:
- `current_timestamp()` - Unix timestamp in seconds
- `current_timestamp_millis()` - Unix timestamp in milliseconds

Both functions exported via `crate::` for easy import.

## COMPLETE

Before: 6 production instances of inline/duplicate timestamp code
After: 0 (all use canonical functions)

Enforcement: aphoria-dev skill updated with "Do Not" rule
Documentation: Canonical functions documented with usage examples
