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
This commit is contained in:
Graham McIntire 2026-01-15 09:36:00 -06:00
parent 97b1e7bb9e
commit c9e4e8d105
No known key found for this signature in database

View file

@ -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