humanizeLastUsed renders last_used_at as "(used 2d ago)" / "(never used)".
(ts sql.NullString, now time.Time)
| 117 | |
| 118 | // humanizeLastUsed renders last_used_at as "(used 2d ago)" / "(never used)". |
| 119 | func humanizeLastUsed(ts sql.NullString, now time.Time) string { |
| 120 | if !ts.Valid || ts.String == "" { |
| 121 | return "(never used)" |
| 122 | } |
| 123 | t, err := time.Parse(time.RFC3339, ts.String) |
| 124 | if err != nil { |
| 125 | return "(used " + ts.String + ")" |
| 126 | } |
| 127 | d := now.Sub(t) |
| 128 | switch { |
| 129 | case d < time.Minute: |
| 130 | return "(used just now)" |
| 131 | case d < time.Hour: |
| 132 | return fmt.Sprintf("(used %dm ago)", int(d.Minutes())) |
| 133 | case d < 24*time.Hour: |
| 134 | return fmt.Sprintf("(used %dh ago)", int(d.Hours())) |
| 135 | default: |
| 136 | return fmt.Sprintf("(used %dd ago)", int(d.Hours()/24)) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // cmdWorkdirAdd registers <path> (making it absolute), auto-detects git |
| 141 | // remote from .git/config, and upserts. Accepts --name and --description |