ask_datetime

SolidGroundUX DocumentationSolidGroundUX
NL

fn: ask_datetime

Purpose

Prompt for an absolute or relative date/time value and normalize it.

Behavior

  • Reuses ask for readline editing, defaults, alignment, and colors.
  • Accepts normal date and datetime values understood by GNU date.
  • Accepts N for now and D for today at 00:00:00.
  • Accepts signed relative values using s, m, h, d, M, and y units.
  • Supports combined relative expressions such as -1d2h30m.
  • Re-prompts until the entered value can be normalized.
  • Displays the resolved ISO-8601 datetime when a shortcut is entered.
  • Stores the accepted value as a local ISO-8601 timestamp.

Options

  • --label TEXT — Prompt label shown before the input field.
  • --var NAME — Shell variable that receives the normalized datetime.
  • --default VALUE — Editable absolute value or SolidGroundUX datetime shortcut.
  • --echo — Echo the normalized value after it has been accepted.
  • --labelwidth WIDTH — Visible width used to align the prompt label.
  • --pad COUNT — Number of spaces inserted before the prompt label.
  • --labelclr ANSI — ANSI sequence used for the label.
  • --inputclr ANSI — ANSI sequence used for the input.
  • --colorize MODE — Colorize mode: none, label, input, or both.

Supported shortcuts

  • N — Current local date and time.
  • D — Current local date at 00:00:00.
  • s — Seconds.
  • m — Minutes.
  • h — Hours.
  • d — Days.
  • M — Months.
  • y — Years.

Outputs (globals)

Variable named by --var, when --var is supplied.

Output

Displays the normalized value after N, D, or a signed relative shortcut. Writes the normalized value to stdout only when --echo is used without --var.

Returns

  • 0 when a valid datetime was accepted.
  • 2 when /dev/tty is unavailable through ask.

Usage

  # Accept an editable relative default and store an ISO-8601 value.
  ask_datetime --label "Changed after" --var CHANGED_AFTER --default "-2h"

  # Accept the current local time with N or a relative offset such as -1d2h30m.
  ask_datetime --label "Run at" --var RUN_AT --default "N"

  # Capture the accepted datetime from stdout instead of assigning a variable.
  RUN_AT="$(ask_datetime --label "Schedule" --default "D" --echo)"