Skip to content

Commit

Permalink
fix: amend GetUTCDate() in telescope module in @observerly/alpacago
Browse files Browse the repository at this point in the history
fix: amend GetUTCDate() in telescope module in @observerly/alpacago
  • Loading branch information
michealroberts committed Jan 3, 2025
1 parent 4d334d0 commit 558cdd4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/alpacago/telescope.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package alpacago
import (
"errors"
"fmt"
"strings"
"time"
)

Expand Down Expand Up @@ -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)
}

/*
Expand Down

0 comments on commit 558cdd4

Please sign in to comment.