-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Proposal: Add time.Until() to the time package #14595
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
Comments
CL https://golang.org/cl/20118 mentions this issue. |
Does it pay for itself? I see only 7 potential users in the standard library:
|
That's 7 places in the standard library that would be somewhat more readable; however, it's a public API so I'm sure there are many more places where it would be useful outside the standard library too. I'd say it pays for itself in adding simplicity, but maybe I'm alone in that? |
We often use the standard library as a proxy for how common a pattern is. Yes, surely there are more than 7 globally. But the question is how often rate-wise this occurs. |
I see; I'd suspect a lot (actually, 7 seems like a pretty large number for the handful of packages in the standard library that will use this sort of thing). For the record, I see 22 uses of |
I got 22 uses of time.Since in the standard library
vs. 7 that could use the proposed time.Until.
|
How is this different than |
It's not, this would be for readability (in the same way that |
@campoy, can you query the Github corpus in BigQuery and see if this proposal would be worthwhile? |
There's in total around 2000 repos (counting forks only once) that could benefit from this feature. SELECT REGEXP_EXTRACT(repo_name, r'.*/(.*)') as project, FLOOR(COUNT(*) / COUNT(DISTINCT repo_name)) as n, FIRST(line) as sample
FROM (
SELECT id, split(content, '\n') as line
FROM [campoy-github:go_files.contents]
HAVING line CONTAINS '.Sub(time.Now())'
) as contents JOIN [campoy-github:go_files.files] as files
ON contents.id = files.id
GROUP BY project
ORDER BY n DESC The 10 projects that would benefit the most are
In my opinion there's some projects that could benefit of this, but it's clearly not a high priority addition to the stdlib. |
I'm in favor of this. time.Since is a great API. time.Until is a fitting parallel. |
Updates #14595 Change-Id: Idf60b3004c7a0ebb59dd48389ab62c854069e09f Reviewed-on: https://go-review.googlesource.com/28073 Run-TryBot: Brad Fitzpatrick <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Andrew Gerrand <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
should change milestone to go1.8? or how to set the milestone label? |
@s7v7nislands it doesn't matter now. The issue is resolved. |
Adds an Until() function that returns the duration until the given time. This compliments the existing Since() function and makes writing expressions that have expiration times more readable; for example: <-After(time.Until(connExpires)): Fixes golang#14595 Change-Id: I87998a924b11d4dad5512e010b29d2da6b123456 Reviewed-on: https://go-review.googlesource.com/20118 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Andrew Gerrand <[email protected]>
Adds an Until() function that returns the duration until the given time. This compliments the existing Since() function and makes writing expressions that have expiration times more readable; for example: <-After(time.Until(connExpires)): Fixes golang#14595 Change-Id: I87998a924b11d4dad5512e010b29d2da6b123456 Reviewed-on: https://go-review.googlesource.com/20118 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Andrew Gerrand <[email protected]>
I'd like to propose that a
time.Until(t time.Time) time.Duration
function be added to the time package to compliment the existingSince()
shortcut. This would make writing expressions with an expiration time a bit more readable:vs.
While it's still fairly obvious what the second one does, it takes a little longer to recognize "sub" as subtraction than just seeing the symbol. Also keeping time expressions more or less readable as english is a nice benefit of having the until shortcut (as you can do with the existing since function).
If this accepted, I've got a CL here for review.
The text was updated successfully, but these errors were encountered: