From ed6ee5aaccb4da9eb2f4c4cd389f9d51f66eadab Mon Sep 17 00:00:00 2001 From: Alex Savin Date: Wed, 9 Jul 2025 09:43:31 -0400 Subject: [PATCH] Enhance JSON unmarshalling in CustomTime types to improve string parsing and add debug logging --- mysubaru.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mysubaru.go b/mysubaru.go index 3b13dac..823bc06 100644 --- a/mysubaru.go +++ b/mysubaru.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "log/slog" + "strings" "time" ) @@ -496,12 +497,13 @@ type CustomTime1 struct { func (ct *CustomTime1) UnmarshalJSON(b []byte) (err error) { // Use the correct layout string for the desired format const layout = "2006-01-02T15:04:05" - // s := strings.Trim(string(b), "\\\"") // Remove surrounding quotes + fmt.Printf("UnmarshalJSON called with: %s\n", string(b)) + s := strings.Trim(string(b), "\\\"") // Remove surrounding quotes if string(b) == "null" { ct.Time = time.Time{} return nil } - ct.Time, err = time.Parse(layout, string(b)) // Parse the string with your custom layout + ct.Time, err = time.Parse(layout, s) // Parse the string with your custom layout return } @@ -514,11 +516,12 @@ type CustomTime2 struct { func (ct *CustomTime2) UnmarshalJSON(b []byte) (err error) { // Use the correct layout string for the desired format const layout = "2006-01-02T15:04:05-0700" - // s := strings.Trim(string(b), "\\\"") // Remove surrounding quotes + fmt.Printf("UnmarshalJSON called with: %s\n", string(b)) + s := strings.Trim(string(b), "\\\"") // Remove surrounding quotes if string(b) == "null" { ct.Time = time.Time{} return nil } - ct.Time, err = time.Parse(layout, string(b)) // Parse the string with your custom layout + ct.Time, err = time.Parse(layout, s) // Parse the string with your custom layout return }