Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/pages: use duration time component

Builds on the last commit to introduce a variant of the time component but for durations. I added a verbose/long duration fmt function based on the existing short duration fmt one, and also renamed the other time fmt functions for clarity.

authored by

uncenter and committed by
Tangled
dce4b41d aea12462

+67 -63
+44 -30
appview/pages/funcmap.go
··· 105 105 s = append(s, values...) 106 106 return s 107 107 }, 108 - "timeFmt": humanize.Time, 109 - "longTimeFmt": func(t time.Time) string { 110 - return t.Format("Jan 2, 2006, 3:04 PM MST") 111 - }, 112 - "iso8601Fmt": func(t time.Time) string { 113 - return t.Format("2006-01-02T15:04:05-07:00") 114 - }, 115 - "commaFmt": humanize.Comma, 116 - "shortTimeFmt": func(t time.Time) string { 108 + "commaFmt": humanize.Comma, 109 + "relTimeFmt": humanize.Time, 110 + "shortRelTimeFmt": func(t time.Time) string { 117 111 return humanize.CustomRelTime(t, time.Now(), "", "", []humanize.RelTimeMagnitude{ 118 112 {time.Second, "now", time.Second}, 119 113 {2 * time.Second, "1s %s", 1}, ··· 126 132 {math.MaxInt64, "a long while %s", 1}, 127 133 }) 128 134 }, 129 - "durationFmt": func(duration time.Duration) string { 135 + "longTimeFmt": func(t time.Time) string { 136 + return t.Format("Jan 2, 2006, 3:04 PM MST") 137 + }, 138 + "iso8601DateTimeFmt": func(t time.Time) string { 139 + return t.Format("2006-01-02T15:04:05-07:00") 140 + }, 141 + "iso8601DurationFmt": func(duration time.Duration) string { 130 142 days := int64(duration.Hours() / 24) 131 143 hours := int64(math.Mod(duration.Hours(), 24)) 132 144 minutes := int64(math.Mod(duration.Minutes(), 60)) 133 145 seconds := int64(math.Mod(duration.Seconds(), 60)) 134 - 135 - chunks := []struct { 136 - name string 137 - amount int64 138 - }{ 139 - {"d", days}, 140 - {"hr", hours}, 141 - {"min", minutes}, 142 - {"s", seconds}, 143 - } 144 - 145 - parts := []string{} 146 - 147 - for _, chunk := range chunks { 148 - if chunk.amount != 0 { 149 - parts = append(parts, fmt.Sprintf("%d%s", chunk.amount, chunk.name)) 150 - } 151 - } 152 - 153 - return strings.Join(parts, " ") 146 + return fmt.Sprintf("P%dD%dH%dM%dS", days, hours, minutes, seconds) 147 + }, 148 + "durationFmt": func(duration time.Duration) string { 149 + return durationFmt(duration, [4]string{"d", "hr", "min", "s"}) 150 + }, 151 + "longDurationFmt": func(duration time.Duration) string { 152 + return durationFmt(duration, [4]string{"days", "hours", "minutes", "seconds"}) 154 153 }, 155 154 "byteFmt": humanize.Bytes, 156 155 "length": func(slice any) int { ··· 277 290 278 291 modifiedSVG := svgStr[:svgTagEnd] + classTag + svgStr[svgTagEnd:] 279 292 return template.HTML(modifiedSVG), nil 293 + } 294 + 295 + func durationFmt(duration time.Duration, names [4]string) string { 296 + days := int64(duration.Hours() / 24) 297 + hours := int64(math.Mod(duration.Hours(), 24)) 298 + minutes := int64(math.Mod(duration.Minutes(), 60)) 299 + seconds := int64(math.Mod(duration.Seconds(), 60)) 300 + 301 + chunks := []struct { 302 + name string 303 + amount int64 304 + }{ 305 + {names[0], days}, 306 + {names[1], hours}, 307 + {names[2], minutes}, 308 + {names[3], seconds}, 309 + } 310 + 311 + parts := []string{} 312 + 313 + for _, chunk := range chunks { 314 + if chunk.amount != 0 { 315 + parts = append(parts, fmt.Sprintf("%d%s", chunk.amount, chunk.name)) 316 + } 317 + } 318 + 319 + return strings.Join(parts, " ") 280 320 }
+8 -4
appview/pages/templates/repo/fragments/time.html
··· 1 1 {{ define "repo/fragments/timeWrapper" }} 2 - <time datetime="{{ .Time | iso8601Fmt }}" title="{{ .Time | longTimeFmt }}">{{ .Content }}</time> 2 + <time datetime="{{ .Time | iso8601DateTimeFmt }}" title="{{ .Time | longTimeFmt }}">{{ .Content }}</time> 3 3 {{ end }} 4 4 5 5 {{ define "repo/fragments/time" }} 6 - {{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (. | timeFmt)) }} 6 + {{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (. | relTimeFmt)) }} 7 7 {{ end }} 8 8 9 9 {{ define "repo/fragments/shortTime" }} 10 - {{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (. | shortTimeFmt)) }} 10 + {{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (. | shortRelTimeFmt)) }} 11 11 {{ end }} 12 12 13 13 {{ define "repo/fragments/shortTimeAgo" }} 14 - {{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (print (. | shortTimeFmt) " ago")) }} 14 + {{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (print (. | shortRelTimeFmt) " ago")) }} 15 + {{ end }} 16 + 17 + {{ define "repo/fragments/duration" }} 18 + <time datetime="{{ . | iso8601DurationFmt }}" title="{{ . | longDurationFmt }}">{{ . | durationFmt }}</time> 15 19 {{ end }}
+5 -9
appview/pages/templates/repo/pipelines/fragments/tooltip.html
··· 10 10 {{ $lastStatus := $all.Latest }} 11 11 {{ $kind := $lastStatus.Status.String }} 12 12 13 - {{ $t := .TimeTaken }} 14 - {{ $time := "" }} 15 - {{ if $t }} 16 - {{ $time = durationFmt $t }} 17 - {{ else }} 18 - {{ $time = printf "%s ago" (shortTimeFmt $pipeline.Created) }} 19 - {{ end }} 20 - 21 13 <div id="left" class="flex items-center gap-2 flex-shrink-0"> 22 14 {{ template "repo/pipelines/fragments/workflowSymbol" $all }} 23 15 {{ $name }} 24 16 </div> 25 17 <div id="right" class="flex items-center gap-2 flex-shrink-0"> 26 18 <span class="font-bold">{{ $kind }}</span> 27 - <time>{{ $time }}</time> 19 + {{ if .TimeTaken }} 20 + {{ template "repo/fragments/duration" .TimeTaken }} 21 + {{ else }} 22 + {{ template "repo/fragments/shortTimeAgo" $pipeline.Created }} 23 + {{ end }} 28 24 </div> 29 25 </div> 30 26 </a>
+5 -10
appview/pages/templates/repo/pipelines/workflow.html
··· 32 32 {{ $lastStatus := $all.Latest }} 33 33 {{ $kind := $lastStatus.Status.String }} 34 34 35 - {{ $t := .TimeTaken }} 36 - {{ $time := "" }} 37 - 38 - {{ if $t }} 39 - {{ $time = durationFmt $t }} 40 - {{ else }} 41 - {{ $time = printf "%s ago" (shortTimeFmt $lastStatus.Created) }} 42 - {{ end }} 43 - 44 35 <div id="left" class="flex items-center gap-2 flex-shrink-0"> 45 36 {{ template "repo/pipelines/fragments/workflowSymbol" $all }} 46 37 {{ $name }} 47 38 </div> 48 39 <div id="right" class="flex items-center gap-2 flex-shrink-0"> 49 40 <span class="font-bold">{{ $kind }}</span> 50 - <time>{{ $time }}</time> 41 + {{ if .TimeTaken }} 42 + {{ template "repo/fragments/duration" .TimeTaken }} 43 + {{ else }} 44 + {{ template "repo/fragments/shortTimeAgo" $lastStatus.Created }} 45 + {{ end }} 51 46 </div> 52 47 </div> 53 48 </a>
+5 -10
appview/pages/templates/repo/pulls/pull.html
··· 277 277 {{ $lastStatus := $all.Latest }} 278 278 {{ $kind := $lastStatus.Status.String }} 279 279 280 - {{ $t := .TimeTaken }} 281 - {{ $time := "" }} 282 - 283 - {{ if $t }} 284 - {{ $time = durationFmt $t }} 285 - {{ else }} 286 - {{ $time = printf "%s ago" (shortTimeFmt $lastStatus.Created) }} 287 - {{ end }} 288 - 289 280 <div id="left" class="flex items-center gap-2 flex-shrink-0"> 290 281 {{ template "repo/pipelines/fragments/workflowSymbol" $all }} 291 282 {{ $name }} 292 283 </div> 293 284 <div id="right" class="flex items-center gap-2 flex-shrink-0"> 294 285 <span class="font-bold">{{ $kind }}</span> 295 - <time>{{ $time }}</time> 286 + {{ if .TimeTaken }} 287 + {{ template "repo/fragments/duration" .TimeTaken }} 288 + {{ else }} 289 + {{ template "repo/fragments/shortTimeAgo" $lastStatus.Created }} 290 + {{ end }} 296 291 </div> 297 292 </div> 298 293 </a>