From bf068a085a55ed350b2f36607a03d9d2299894fb Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Wed, 15 May 2024 16:05:24 +0100 Subject: [PATCH] fix: amend GetUTCDate() in telescope module in @observerly/alpacago. fix: amend GetUTCDate() in telescope module in @observerly/alpacago. --- coverage.txt | 4 ++-- pkg/alpacago/telescope.go | 8 ++++++-- pkg/alpacago/telescope_test.go | 12 +++--------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/coverage.txt b/coverage.txt index 5e7c424..8d978f3 100644 --- a/coverage.txt +++ b/coverage.txt @@ -380,5 +380,5 @@ github.com/observerly/alpacago/pkg/alpacago/telescope.go:1039.81,1049.2 3 1 github.com/observerly/alpacago/pkg/alpacago/telescope.go:1057.48,1059.2 1 1 github.com/observerly/alpacago/pkg/alpacago/telescope.go:1067.54,1077.2 3 15 github.com/observerly/alpacago/pkg/alpacago/telescope.go:1085.54,1087.2 1 1 -github.com/observerly/alpacago/pkg/alpacago/telescope.go:1098.53,1102.2 3 1 -github.com/observerly/alpacago/pkg/alpacago/telescope.go:1113.57,1126.2 4 1 +github.com/observerly/alpacago/pkg/alpacago/telescope.go:1098.53,1105.2 4 1 +github.com/observerly/alpacago/pkg/alpacago/telescope.go:1116.57,1129.2 4 1 diff --git a/pkg/alpacago/telescope.go b/pkg/alpacago/telescope.go index 25a2272..2447d6b 100644 --- a/pkg/alpacago/telescope.go +++ b/pkg/alpacago/telescope.go @@ -1097,8 +1097,12 @@ Z indicating the 'Zulu', UTC time zone. */ func (t *Telescope) GetUTCDate() (time.Time, error) { utc, err := t.Alpaca.GetStringResponse("telescope", t.DeviceNumber, "utcdate") - date, _ := time.Parse("yyyy-MM-ddTHH:mm:ss.fffffffZ", utc) - return date, err + + if err != nil { + return time.Time{}, err + } + + return time.Parse("2006-01-02T15:04:05.000", utc) } /* diff --git a/pkg/alpacago/telescope_test.go b/pkg/alpacago/telescope_test.go index 184caba..01630aa 100644 --- a/pkg/alpacago/telescope_test.go +++ b/pkg/alpacago/telescope_test.go @@ -1126,20 +1126,14 @@ func TestNewTelescopeGetTrackingRate(t *testing.T) { } func TestNewTelescopeGetUTCDate(t *testing.T) { - var got, err = telescope.GetUTCDate() - - var want time.Time = time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC) + var _, err = telescope.GetUTCDate() if err != nil { - t.Errorf("got %q, wanted %q", err, want.String()) - } - - if got != want { - t.Errorf("got %q, wanted %q", got, want.String()) + t.Errorf("got %q", err) } if telescope.Alpaca.ErrorNumber != 0 && telescope.Alpaca.ErrorMessage != "" { - t.Errorf("got %q, wanted %q", telescope.Alpaca.ErrorMessage, want.String()) + t.Errorf("got %q", telescope.Alpaca.ErrorMessage) } }