diff options
Diffstat (limited to 'web/views.go')
| -rw-r--r-- | web/views.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/web/views.go b/web/views.go new file mode 100644 index 0000000..29f3c4f --- /dev/null +++ b/web/views.go @@ -0,0 +1,52 @@ +package web + +import ( + "fmt" + "time" + + "github.com/martinlehoux/biking_home/rides" +) + +type RideView struct { + rides.Ride + Cotacol string + CotacolPer100Km string +} + +type SyncPageData struct { + From string + To string + Error string + Notice string + HasAuth bool +} + +func formatRideDate(value time.Time) string { + return value.Local().Format("02 Jan 2006, 15:04") +} + +func formatDistance(meters float64) string { + return fmt.Sprintf("%.1f km", meters/1000) +} + +func formatDuration(seconds int64) string { + hours := seconds / 3600 + minutes := (seconds % 3600) / 60 + return fmt.Sprintf("%dh %02dm", hours, minutes) +} + +func formatElevation(meters float64) string { + return fmt.Sprintf("%.0f m", meters) +} + +func formatCotacol(score float64) string { + return fmt.Sprintf("%.1f", score) +} + +func formatCotacolPer100Km(score, distanceM float64) string { + distanceKm := distanceM / 1000 + if distanceKm <= 0 { + return "-" + } + return fmt.Sprintf("%.1f", score*100/distanceKm) +} |