Memory.Presentation (fnord v0.9.29)

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 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_line(mem, now)

@spec age_line(:error | Memory.t() | term(), 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.
  • If the first argument is :error or any non-struct value (e.g. a parse error), this will return "Age: unknown (missing timestamps)".

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(:error | Memory.t() | term(), 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.

If the first argument is :error or any non-struct value, this function will return nil (no warning).