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

time.Time is loosing precision when saved/loaded #242

Open
tgirod opened this issue Dec 19, 2018 · 1 comment
Open

time.Time is loosing precision when saved/loaded #242

tgirod opened this issue Dec 19, 2018 · 1 comment

Comments

@tgirod
Copy link

tgirod commented Dec 19, 2018

Consider this:

type Student struct {
	ID        int
	CreatedAt time.Time
}

func main() {
	s := Student{
		ID:        1,
		CreatedAt: time.Now(),
	}
	fmt.Println("original")
	fmt.Println(s)
	// db, _ := storm.Open("my.db", storm.Codec(gob.Codec))
	db, _ := storm.Open("my.db")
	if err := db.Save(&s); err != nil {
		panic(err)
	}
	fmt.Println("saved")
	fmt.Println(s)

	s2 := new(Student)
	if err := db.One("ID", s.ID, s2); err != nil {
		panic(err)
	}
	fmt.Println("fetched")
	fmt.Println(*s2)
}

Simple: the student is saved in the database, then reloaded. I expect the two objects to be the same. Here is what I get:

go run test.go 
original
{1 2018-12-19 10:27:11.293548697 +0100 CET m=+0.000199613}
saved
{1 2018-12-19 10:27:11.293548697 +0100 CET m=+0.000199613}
fetched
{1 2018-12-19 10:27:11.293548697 +0100 CET}

Why is time.Time loosing precision in the process ? I have the same problem with gob.Codec.

@asdine
Copy link
Owner

asdine commented Dec 22, 2018

This is not related to Storm, this is related to the way JSON and Gob encode and decode time.
If you need more information you can take a look at this issue: golang/go#17875

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

2 participants