-
Notifications
You must be signed in to change notification settings - Fork 460
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
Introduce type for Unix timestamps in JSON #6883
Conversation
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nicely done, left only a single question
pkg/util/time.go
Outdated
} | ||
switch { | ||
case i == 0: | ||
*t = JSONSecondsTimestamp(time.Time{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't i==0
equivalent to time.Unix(0, 0)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not.
time.Unix(0, 0)
is1970-01-01 00:00:00 +0000 UTC
.time.Time{}
is0001-01-01 00:00:00 +0000 UTC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if the json doc contains "time": 0
we treat this as 0001-01-01
, but it could have been intended as 1970-01-01
(which is also valid)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and also now the code changes what it receives
0001-01-01 --unmarshal--> 0 --marshal--> 1970-01-01
it started with one date, but ended up with another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're correct and your examples are valid. Given the special nature of both values, I don't think this is a showstopper though.
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
Negative of this approach is that That's disappointing. I've marked this PR as draft for this reason. |
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
I've updated the PR, now the type is just:
This works with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, LGTM
pkg/util/time_test.go
Outdated
t.Run(tc.json, func(t *testing.T) { | ||
out, err := json.Marshal(tc.obj) | ||
require.NoError(t, err) | ||
require.Equal(t, tc.json, string(out)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's require.JSONEq which is less flaky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's useful.
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
What this PR does
This PR shows how we could replace
int64
fields in our JSON structs that we use for storing Unix timestamps with typed field.Benefit is stronger typing and fewer ad-hoc conversions between units.
In this PR I've modified tenant deletion marks only to use this format, but there are other fields (deletion marker, no compact marker, bucket index) where we could use this.
Which issue(s) this PR fixes or relates to
Inspired by changes in #6848.
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
.about-versioning.md
updated with experimental features.