intrepidshape/elm-web3-ui/4.0.0

Web3.Ui.RelativeTime

Compact relative-time string for transaction ages, position open dates, graduation timestamps -- anywhere a dapp shows "how long ago".

Web3.Ui.RelativeTime.view [] { nowSec = model.nowSec, atSec = tx.timestamp }
--> "2m ago" / "3h ago" / "1d ago" / "Apr 12"

For non-Html callers (e.g., row labels):

Web3.Ui.RelativeTime.format { nowSec = model.nowSec, atSec = tx.timestamp }
--> "2m ago"

CSS class on the rendered span: web3-relativetime. The full RFC-style timestamp (ISO-like seconds) is set as a title attribute for hover.

view : List (Attribute msg) -> Config -> Html msg

Render the relative time string inside a span with a title showing the absolute Unix seconds for accessibility / hover.

type alias Config =
{ nowSec : Int
, atSec : Int
}

The instant being described and the instant it is described from, both in Unix seconds.

format : Config -> String

Pure helper: convert a Unix-seconds delta into a human string.

Buckets:

  • < 60s -> "Ns ago"
  • < 60m -> "Nm ago"
  • < 24h -> "Nh ago"
  • < 30d -> "Nd ago"
  • else -> "Nw ago" (weeks; coarse beyond a month)

Negative deltas (future) render as "in Ns" / "in Nm" / etc.