Files
weatherapi/internal/adapters/inbound/httpapi/presenter/helpers.go
Eric Rakestraw b3ac19a65d
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
Add timezone support to /forecast/hourly endpoint
2026-03-26 20:06:17 -05:00

90 lines
1.4 KiB
Go

// helpers.go contains shared pointer and scalar conversion helpers.
// Layer: adapters/inbound/httpapi/presenter helper functions.
package presenter
import (
"math"
"time"
)
func celsiusToFahrenheitPtr(v *float64) *float64 {
if v == nil {
return nil
}
out := (*v * celsiusToFahrenheitScale) + celsiusToFahrenheitOffset
return &out
}
func scalePtr(v *float64, factor float64) *float64 {
if v == nil {
return nil
}
out := *v * factor
return &out
}
func copyFloat64Ptr(v *float64) *float64 {
if v == nil {
return nil
}
out := *v
return &out
}
func copyBoolPtr(v *bool) *bool {
if v == nil {
return nil
}
out := *v
return &out
}
func copyTimePtr(v *time.Time) *time.Time {
if v == nil {
return nil
}
out := *v
return &out
}
func inLocationTime(v time.Time, loc *time.Location) time.Time {
if loc == nil {
return v
}
return v.In(loc)
}
func inLocationTimePtr(v *time.Time, loc *time.Location) *time.Time {
if v == nil {
return nil
}
out := inLocationTime(*v, loc)
return &out
}
func boolText(v *bool) string {
if v == nil {
return ""
}
if *v {
return "true"
}
return "false"
}
func roundedPtr(v *float64, precision int) *float64 {
if v == nil {
return nil
}
out := roundFloat(*v, precision)
return &out
}
func roundFloat(v float64, precision int) float64 {
if precision <= 0 {
return math.Round(v)
}
factor := math.Pow10(precision)
return math.Round(v*factor) / factor
}