From 558cdd42203ca112620b622570cb3f8f96b1281f Mon Sep 17 00:00:00 2001 From: michealroberts Date: Fri, 3 Jan 2025 17:16:25 +0000 Subject: [PATCH] fix: amend GetUTCDate() in telescope module in @observerly/alpacago fix: amend GetUTCDate() in telescope module in @observerly/alpacago --- pkg/alpacago/telescope.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/alpacago/telescope.go b/pkg/alpacago/telescope.go index 2447d6b..412a830 100644 --- a/pkg/alpacago/telescope.go +++ b/pkg/alpacago/telescope.go @@ -3,6 +3,7 @@ package alpacago import ( "errors" "fmt" + "strings" "time" ) @@ -1102,7 +1103,24 @@ func (t *Telescope) GetUTCDate() (time.Time, error) { return time.Time{}, err } - return time.Parse("2006-01-02T15:04:05.000", utc) + // Ensure the string ends with 'Z' + if !strings.HasSuffix(utc, "Z") { + utc += "Z" + } + + // Ensure there are at least three fractional digits + if dotIndex := strings.Index(utc, "."); dotIndex != -1 { + fractional := utc[dotIndex+1 : len(utc)-1] // Exclude 'Z' + if len(fractional) < 3 { + utc = utc[:dotIndex+1] + fractional + strings.Repeat("0", 3-len(fractional)) + "Z" + } + } else { + // If no fractional seconds, add .000 + utc = strings.TrimSuffix(utc, "Z") + ".000Z" + } + + // Use RFC3339 layout which expects 'Z' and fractional seconds + return time.Parse(time.RFC3339, utc) } /*