From c9e4e8d105a1284155859c0685e8c754b4c3adf1 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 15 Jan 2026 09:36:00 -0600 Subject: [PATCH] Show pipeline creation time as relative 'X ago' format - Added format_time_ago() function - Handles both GNU date (Linux) and BSD date (macOS) - Properly parses ISO 8601 timestamps with UTC timezone - Shows: 30s ago, 5m ago, 2h ago, 3d ago - Changed 'Created' field from raw timestamp to human-readable format --- scripts/monitor-deploy.sh | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/scripts/monitor-deploy.sh b/scripts/monitor-deploy.sh index 492d37d2..14e22bfc 100755 --- a/scripts/monitor-deploy.sh +++ b/scripts/monitor-deploy.sh @@ -185,6 +185,51 @@ format_duration() { fi } +format_time_ago() { + local timestamp=$1 + if [ -z "$timestamp" ] || [ "$timestamp" = "null" ]; then + echo "Unknown" + return + fi + + # Convert ISO 8601 timestamp to Unix epoch + # Handle both GNU date and BSD date (macOS) + local created_epoch + if date --version >/dev/null 2>&1; then + # GNU date + created_epoch=$(date -d "$timestamp" +%s 2>/dev/null) + else + # BSD date (macOS) - strip milliseconds and timezone, then parse as UTC + local clean_timestamp=$(echo "$timestamp" | sed 's/\.[0-9]*Z$//') + created_epoch=$(date -j -u -f "%Y-%m-%dT%H:%M:%S" "$clean_timestamp" +%s 2>/dev/null) + fi + + if [ -z "$created_epoch" ]; then + echo "Unknown" + return + fi + + local now=$(date +%s) + local seconds_ago=$((now - created_epoch)) + + # Handle negative values (future timestamps) + if [ $seconds_ago -lt 0 ]; then + seconds_ago=$((seconds_ago * -1)) + echo "in ${seconds_ago}s" + return + fi + + if [ $seconds_ago -lt 60 ]; then + echo "${seconds_ago}s ago" + elif [ $seconds_ago -lt 3600 ]; then + echo "$((seconds_ago / 60))m ago" + elif [ $seconds_ago -lt 86400 ]; then + echo "$((seconds_ago / 3600))h ago" + else + echo "$((seconds_ago / 86400))d ago" + fi +} + print_header() { clear echo -e "${CYAN}╔════════════════════════════════════════════════════════════════╗${NC}" @@ -220,7 +265,7 @@ monitor_pipeline() { echo -e "${BLUE}Branch:${NC} $branch" echo -e "${BLUE}Local HEAD:${NC} $local_sha" echo -e "${BLUE}Pipeline:${NC} #$pipeline_id" - echo -e "${BLUE}Created:${NC} $pipeline_created" + echo -e "${BLUE}Created:${NC} $(format_time_ago "$pipeline_created")" echo -e "${BLUE}Commit:${NC} ${pipeline_sha:0:8}" # Warn if local commit doesn't match pipeline commit