Yōten: A social tracker for your language learning journey built on the atproto.

feat: make dates more user friendly

brookjeynes.dev 03fc6034 49c8f3cb

verified
+27 -3
+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 - <span>{ params.StudySession.StudySession.Duration.String() }</span> 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 - import "strings" 3 + import ( 4 + "fmt" 5 + "strings" 6 + "time" 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 + 21 + func FormatDuration(d time.Duration) string { 22 + hours := int(d.Hours()) 23 + minutes := int(d.Minutes()) % 60 24 + seconds := int(d.Seconds()) % 60 25 + 26 + if hours > 0 { 27 + if minutes > 0 { 28 + return fmt.Sprintf("%dh %dm", hours, minutes) 29 + } 30 + return fmt.Sprintf("%dh", hours) 31 + } 32 + if minutes > 0 { 33 + if seconds > 0 { 34 + return fmt.Sprintf("%dm %ds", minutes, seconds) 35 + } 36 + return fmt.Sprintf("%dm", minutes) 37 + } 38 + return fmt.Sprintf("%ds", seconds) 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 - <p class="text-2xl font-bold">{ params.TotalStudyTime }</p> 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>