Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DockerHub] use float64 instead of float32 for time fields #116

Open
tom24d opened this issue Jul 24, 2020 · 0 comments
Open

[DockerHub] use float64 instead of float32 for time fields #116

tom24d opened this issue Jul 24, 2020 · 0 comments

Comments

@tom24d
Copy link

tom24d commented Jul 24, 2020

I consider this is not a bug, it's UX thing.

When I run simple golang:

type A struct{
	PushedAt float32 `json:"pushed_at"`
}

func main() {
	unixT := float32(1.5229495e+09)
	a := A{
		PushedAt: unixT,
	}
	b, _ := json.Marshal(a)
	var c A
	json.Unmarshal([]byte(b), &c)
	fmt.Printf("%+v\n", a)
	fmt.Printf("%+v\n", c)
	fmt.Printf("%d\n", int64(a.PushedAt))
}

then I got the output:

{PushedAt:1.5229495e+09}
{PushedAt:1.5229495e+09}
1522949504

You can see there is a diff when converting a.PushedAt into int64.
When I use this number with time.Unix(sec int64, nsec int64), this makes severe difference of the time.
If we use float64 then we can get right answer.

How about using float64 instead??
Any pointers would much be appreciated.

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant