From 46f2588144211ec3361995ad7adb4cf5fc3a75fd Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Thu, 9 May 2019 11:55:23 +0200
Subject: [PATCH] Fix time format for coach sequence API

---
 client.go     |  2 +-
 types_util.go | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/client.go b/client.go
index 6100db5..0ba9b22 100644
--- a/client.go
+++ b/client.go
@@ -290,7 +290,7 @@ func (c *ApiClient) CoachSequence(line string, date time.Time) (CoachSequence, e
 func (c *ApiClient) loadCoachSequence(line string, date time.Time) (CoachSequence, error) {
 	var err error
 
-	uri := fmt.Sprintf("%s/%s/%s", c.CoachSequenceBaseUrl, line, date.Format(TimeLayoutShort))
+	uri := fmt.Sprintf("%s/%s/%s", c.CoachSequenceBaseUrl, line, date.Format(TimeLayoutMediumShort))
 	glog.Infof("Loading CoachSequence %s %s", line, date.Format(time.RFC3339))
 
 	var coachSequence CoachSequence
diff --git a/types_util.go b/types_util.go
index ba55d62..f45ebfb 100644
--- a/types_util.go
+++ b/types_util.go
@@ -105,6 +105,42 @@ func (t *timeShort) Value() *time.Time {
 	}
 }
 
+type timeMediumShort struct {
+	time.Time
+}
+
+const TimeLayoutMediumShort = "200601021504"
+
+func (t *timeMediumShort) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
+	if t == nil || t.IsZero() {
+		return xml.Attr{}, nil
+	} else {
+		return xml.Attr{
+			Name:  name,
+			Value: t.Format(TimeLayoutMediumShort),
+		}, nil
+	}
+}
+
+func (t *timeMediumShort) UnmarshalXMLAttr(attr xml.Attr) error {
+	if attr.Value != "" {
+		value, err := time.Parse(TimeLayoutMediumShort, attr.Value)
+		if err != nil {
+			return err
+		}
+		t.Time = value
+	}
+	return nil
+}
+
+func (t *timeMediumShort) Value() *time.Time {
+	if t != nil {
+		return &t.Time
+	} else {
+		return nil
+	}
+}
+
 type timeMedium struct {
 	time.Time
 }
-- 
GitLab