helpers.go 518 B

12345678910111213141516171819202122232425
  1. package views
  2. import "fmt"
  3. // SongCount holds the played/total song counts for a jam.
  4. type SongCount struct {
  5. Played int
  6. Total int
  7. }
  8. // dateOnly extracts the YYYY-MM-DD prefix from a PocketBase datetime string.
  9. func dateOnly(s string) string {
  10. if len(s) >= 10 {
  11. return s[:10]
  12. }
  13. return s
  14. }
  15. // songCountDisplay formats a played/total pair as "X / Y", or "" when total is 0.
  16. func songCountDisplay(sc SongCount) string {
  17. if sc.Total == 0 {
  18. return ""
  19. }
  20. return fmt.Sprintf("%d / %d", sc.Played, sc.Total)
  21. }