-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[WIP] Add Unix Timestamp support for last_read_at in notifications API #24918
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
[WIP] Add Unix Timestamp support for last_read_at in notifications API #24918
Conversation
The swagger docs still specify this parameter as |
IMO the new logic could be put into a separate util function, and use more specific tests to cover it. It would benefit other "date/time" parameters in the future. |
Yes, call it |
Also, I think it'd be better to support millisecond precision, e.g. parse via UnixMilli. This is also the default precision in JavaScript, fwiw. Should be noted in the API docs, e.g. update the field comment. |
That needs more designs. The problem is: when you see an integer or number, what do you think it should be for a "time"? I prefer to use International System of Units (SI) , eg: 1 means 1 second. 1.001 means 1 second and 1 millisecond, then microsecond and nanosecond could also be supported. |
Floating point numbers are a bit unergonomic, but possible, yes. Whatever we do, we should specify in the API docs. I personally would still do milliseconds, it's just precise enough to be generally useful. For example, Grafana also accepts unix timestamps as milliseconds as well as special identifiers like |
99640d7
to
550ac86
Compare
modules/timeutil/datetime.go
Outdated
case int64: | ||
switch { | ||
case val > 946684800000000: // 2999-12-31 00:00:00 in milliseconds | ||
return time.UnixMicro(val), nil | ||
case val > 946645200000: // 2000-01-01 00:00:00 in milliseconds | ||
return time.UnixMilli(val), nil | ||
default: | ||
return time.Unix(val, 0), nil | ||
} |
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.
I have objection for doing so. Keeping "guessing the unit" is quite fragile.
Either it strictly follows the Golang's time (int64 as nanosecond)
Or it strictly follows SI, use second as its unit, and use "0.001" for 1 millisecond (I prefer this way). There is no "float number" problem, because the time could be passed as a string, and split it by the dot ".
" if the caller doesn't want to use float.
I do not think it should introduce another time unit in Gitea. At the moment, Gitea only uses 2 kinds of units:
Introducing more units only increases the difficulty of the maintainability The SI unit (second) works well and is consistent with |
Support for the But in JavaScript standard for the timestamp is in milliseconds. Ideally I'd limit to the extra I looked at the GitHub API and they only use date in format: |
I think the |
I'm fine with float seconds instead of int milliseconds I guess. |
I removed From now
|
Would it be much work to have all |
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.
Overall LGTM. Some nits.
}, | ||
{ | ||
value: 0, | ||
expected: int64(-62135596800), |
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.
If there is an error, there shouldn't be expected
(it can be covered by assert.True(t, actual.IsZero())
)
Co-authored-by: wxiaoguang <[email protected]>
Stale? |
Stale. Feel free to reopen. |
Should fix 2nd point of the issue #24574
Now
last_read_at
parameter in notification API supports following value formats: