You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, apologies if I have missed the correct way of handling this in the documentation.
OS: Windows and Linux via WSL2
GO Version: 1.23.2
Pkg Version: v0.6.17
Describe the bug
I'm querying an API where most timestamps play nice and are handled by 'json.Unmarshal'. However, there is API endpoint that returns a date that matches this format '2006-01-02T15:04:05' which is not handled by default. When I implement a custom unmarshall receiver on a type alias, then dump.Print does not print the timestamp correctly.
type RestorePoint struct {
Timestamp RestorePointTimestamp `json:"timestamp"`
InUse bool `json:"in_use"`
UsageInitiator string `json:"usage_initiator"`
}
type RestorePointTimestamp time.Time
func (t *RestorePointTimestamp) UnmarshalJSON(b []byte) error {
value := strings.Trim(string(b), `"`) //get rid of "
if value == "" || value == "null" {
return nil
}
out, err := time.Parse("2006-01-02T15:04:05", value) //parse time
if err != nil {
return err
}
*t = RestorePointTimestamp(out) //set result using the pointer
return nil
}
When I dump out the struct using dump.Print, the timestamp is not printed as its underlying time.Time format. See below.
As you can see it prints wall, ext and loc instead of the underlying time.Time. Here is an example from another part of the API that does have a clean time format and prints as I would expect.
To Reproduce
See the code here: [https://play.golang.com/p/oCINSaKIogT]
import (
"fmt""github.com/gookit/goutil/dump""time"
)
vardateValue="2024-10-02T19:02:46"typeRestorePointTimestamp time.TimetypeNormalRestorestruct {
TimeStamp time.Time
}
typeCustomRestorestruct {
TimeStampRestorePointTimestamp
}
funcmain() {
fmt.Println()
fmt.Println("Please note this is normally handles as a custom Unmarshall method for the JSON package")
normal, _:=time.Parse("2006-01-02T15:04:05", dateValue)
normalRestore:=NormalRestore{
TimeStamp: normal,
}
custom, _:=time.Parse("2006-01-02T15:04:05", dateValue)
customRestore:=CustomRestore{
TimeStamp: RestorePointTimestamp(custom),
}
fmt.Println()
fmt.Println("This is how I'd like to see the date to output:")
dump.Print(normalRestore)
fmt.Println()
fmt.Println()
fmt.Println("This is how what I actuall get:")
dump.Print(customRestore)
}
Expected behavior
dump.Print for the custom timestamp I'd like to see this.
TimeStamp: time.Time(2024-10-02T19:02:46Z)
Additional context
The text was updated successfully, but these errors were encountered:
First of all, apologies if I have missed the correct way of handling this in the documentation.
Describe the bug
I'm querying an API where most timestamps play nice and are handled by 'json.Unmarshal'. However, there is API endpoint that returns a date that matches this format '2006-01-02T15:04:05' which is not handled by default. When I implement a custom unmarshall receiver on a type alias, then dump.Print does not print the timestamp correctly.
When I dump out the struct using dump.Print, the timestamp is not printed as its underlying time.Time format. See below.
As you can see it prints wall, ext and loc instead of the underlying time.Time. Here is an example from another part of the API that does have a clean time format and prints as I would expect.
To Reproduce
See the code here: [https://play.golang.com/p/oCINSaKIogT]
Expected behavior
dump.Print for the custom timestamp I'd like to see this.
TimeStamp: time.Time(2024-10-02T19:02:46Z)
Additional context
The text was updated successfully, but these errors were encountered: