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

Update TimeStamp to be time.Duration not integer #10

Open
tylerwince opened this issue Mar 18, 2018 · 0 comments
Open

Update TimeStamp to be time.Duration not integer #10

tylerwince opened this issue Mar 18, 2018 · 0 comments

Comments

@tylerwince
Copy link
Member

The current structs have TimeStamp set to be an int when it is probably better served to be a time.Duration object.

We will likely need to update the UnmarshalJSON of some of these to get everything to work correctly. Something like the following:

type HarvestInfo struct {
	TimeStamp  timedur
	Difficulty int64
	TotalFee   int64
	ID         int64
	Height     int64
}

type timedur struct {
	time.Duration
}

func (td *timedur) UnmarshalJSON(b []bytes) error {
    timestamp, err := strconv.ParseFloat(string(b), 0)
    if err != nil {
        return err
    }
    td.Duration = time.Duration(timestamp) * time.Second
    return nil
}

Not sure this is the best approach, but it is tested in playground and works
https://play.golang.org/p/Voi-DFkZ-qh

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

No branches or pull requests

1 participant