ficing all the build errors - checkpoint 2

This commit is contained in:
2025-08-28 13:01:33 -07:00
parent c33a8a3c98
commit c1d3264e53
5 changed files with 190 additions and 82 deletions

View File

@@ -1,6 +1,7 @@
package api
import (
"encoding/json"
"time"
)
@@ -22,6 +23,44 @@ func (t Time) Format(layout string) string {
return time.Time(t).Format(layout)
}
// UnmarshalJSON implements json.Unmarshaler interface
func (t *Time) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
// Try multiple time formats that Garmin might use
formats := []string{
"2006-01-02T15:04:05.000Z",
"2006-01-02T15:04:05Z",
"2006-01-02T15:04:05.000",
"2006-01-02T15:04:05",
time.RFC3339,
time.RFC3339Nano,
}
for _, format := range formats {
if parsedTime, err := time.Parse(format, s); err == nil {
*t = Time(parsedTime)
return nil
}
}
// If none of the formats work, try parsing as RFC3339
parsedTime, err := time.Parse(time.RFC3339, s)
if err != nil {
return err
}
*t = Time(parsedTime)
return nil
}
// MarshalJSON implements json.Marshaler interface
func (t Time) MarshalJSON() ([]byte, error) {
return json.Marshal(time.Time(t).Format(time.RFC3339))
}
// BodyComposition represents body composition metrics from Garmin Connect
type BodyComposition struct {
BoneMass float64 `json:"boneMass"` // Grams
@@ -35,4 +74,4 @@ type BodyComposition struct {
type BodyCompositionRequest struct {
StartDate Time `json:"startDate"`
EndDate Time `json:"endDate"`
}
}