tangled
alpha
login
or
join now
yoten.app
/
yoten
17
fork
atom
Yōten: A social tracker for your language learning journey built on the atproto.
17
fork
atom
overview
issues
pulls
pipelines
feat: make dates more user friendly
brookjeynes.dev
5 months ago
03fc6034
49c8f3cb
verified
This commit was signed with the committer's
known signature
.
brookjeynes.dev
SSH Key Fingerprint:
SHA256:N3n3PCBSiXfS6EHlmGdx+LMEruJMj6FS2hqaXyfsw0s=
+27
-3
3 changed files
expand all
collapse all
unified
split
internal
server
views
partials
study-session.templ
utils.go
stats.templ
+1
-1
internal/server/views/partials/study-session.templ
···
164
164
<div class="flex flex-col sm:flex-row sm:items-center gap-2 text-sm text-text-muted">
165
165
<div class="flex items-center gap-1">
166
166
<i class="w-4 h-4" data-lucide="clock"></i>
167
167
-
<span>{ params.StudySession.StudySession.Duration.String() }</span>
167
167
+
<span>{ FormatDuration(params.StudySession.StudySession.Duration) }</span>
168
168
</div>
169
169
<div class="flex items-center gap-1">
170
170
<i class="w-4 h-4" data-lucide="calendar"></i>
+25
-1
internal/server/views/partials/utils.go
···
1
1
package partials
2
2
3
3
-
import "strings"
3
3
+
import (
4
4
+
"fmt"
5
5
+
"strings"
6
6
+
"time"
7
7
+
)
4
8
5
9
func SanitiseHtmlId(s string) string {
6
10
var idSanitizer = strings.NewReplacer(
···
13
17
)
14
18
return idSanitizer.Replace(s)
15
19
}
20
20
+
21
21
+
func FormatDuration(d time.Duration) string {
22
22
+
hours := int(d.Hours())
23
23
+
minutes := int(d.Minutes()) % 60
24
24
+
seconds := int(d.Seconds()) % 60
25
25
+
26
26
+
if hours > 0 {
27
27
+
if minutes > 0 {
28
28
+
return fmt.Sprintf("%dh %dm", hours, minutes)
29
29
+
}
30
30
+
return fmt.Sprintf("%dh", hours)
31
31
+
}
32
32
+
if minutes > 0 {
33
33
+
if seconds > 0 {
34
34
+
return fmt.Sprintf("%dm %ds", minutes, seconds)
35
35
+
}
36
36
+
return fmt.Sprintf("%dm", minutes)
37
37
+
}
38
38
+
return fmt.Sprintf("%ds", seconds)
39
39
+
}
+1
-1
internal/server/views/stats.templ
···
18
18
</div>
19
19
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
20
20
<div class="card text-center">
21
21
-
<p class="text-2xl font-bold">{ params.TotalStudyTime }</p>
21
21
+
<p class="text-2xl font-bold">{ partials.FormatDuration(params.TotalStudyTime) }</p>
22
22
<div class="text-xs text-text-muted flex items-center justify-center gap-1 mt-1">
23
23
<i class="w-4 h-4" data-lucide="clock"></i>
24
24
<p class="text-xs">Total Study Time</p>