Memory.Presentation (fnord v0.8.92)

View Source

Helpers for presenting %Memory{} metadata to humans.

This module is intentionally small and pure (no I/O) so it can be reused by:

Timestamps are stored on %Memory{} as ISO8601 strings (DateTime.to_iso8601/1).

Summary

Functions

Returns the age in whole days since dt relative to now.

Returns an "Age" line for a memory.

Parse an ISO8601 timestamp string into a DateTime.

Returns an optional warning line based on how long ago the memory was updated.

Types

iso8601()

@type iso8601() :: binary()

Functions

age_days(dt, now)

@spec age_days(DateTime.t(), DateTime.t()) :: non_neg_integer()

Returns the age in whole days since dt relative to now.

If dt is in the future, returns 0.

age_line(mem, now)

@spec age_line(Memory.t(), DateTime.t()) :: binary()

Returns an "Age" line for a memory.

Examples:

  • "Age: unknown (missing timestamps)"
  • "Age: 312 days (updated 12 days ago)"

Notes:

  • Uses updated_at if present; otherwise uses inserted_at.
  • Uses now for deterministic testing.

parse_ts(ts)

@spec parse_ts(nil | iso8601()) :: {:ok, DateTime.t()} | :error

Parse an ISO8601 timestamp string into a DateTime.

Returns {:ok, dt} or :error.

warning_line(mem, now, opts \\ [])

@spec warning_line(Memory.t(), DateTime.t(), keyword()) :: binary() | nil

Returns an optional warning line based on how long ago the memory was updated.

  • If updated_at is missing/unparseable, returns nil.
  • If updated_days >= strong_days, returns a strong warning.
  • Else if updated_days >= mild_days, returns a mild warning.
  • Else returns nil.

This is intended as a gentle prompt to check for cobwebs.