Change time zone to central and remove double timezone listing
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
@ -32,6 +33,22 @@ type Team struct {
|
||||
} `json:"names"`
|
||||
}
|
||||
|
||||
// Convert time from Eastern to Central
|
||||
func convertToCentralTime(easternTime string) (string, error) {
|
||||
parsedTime, err := time.Parse("03:04PM ET", easternTime)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error parsing time: %w", err)
|
||||
}
|
||||
|
||||
centralLocation, err := time.LoadLocation("America/Chicago")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error loading Central Time location: %w", err)
|
||||
}
|
||||
|
||||
centralTime := parsedTime.In(centralLocation)
|
||||
return centralTime.Format("03:04 PM"), nil
|
||||
}
|
||||
|
||||
func GetGameInfo(teamName string) string {
|
||||
teamName = strings.TrimSpace(teamName)
|
||||
week := ""
|
||||
@ -90,8 +107,13 @@ func GetGameInfo(teamName string) string {
|
||||
game.Game.Home.Names.Short, game.Game.Home.Score,
|
||||
period, game.Game.ContestClock)
|
||||
} else if game.Game.GameState == "pre" {
|
||||
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s ET",
|
||||
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, game.Game.StartTime)
|
||||
centralTime, err := convertToCentralTime(game.Game.StartTime)
|
||||
if err != nil {
|
||||
log.Printf("Time conversion error: %v", err)
|
||||
centralTime = game.Game.StartTime // Fall back to the original if conversion fails
|
||||
}
|
||||
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s CT",
|
||||
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, centralTime)
|
||||
} else if game.Game.GameState == "final" {
|
||||
gameInfo = fmt.Sprintf("Final: %s: **%s** %s: **%s**",
|
||||
game.Game.Away.Names.Short, game.Game.Away.Score,
|
||||
@ -108,4 +130,3 @@ func GetGameInfo(teamName string) string {
|
||||
|
||||
return "No game found for the specified team."
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user