-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Expose Time#total_seconds in public API #6661
Expose Time#total_seconds in public API #6661
Conversation
49e0b73
to
130d214
Compare
Unless you have clear use cases, this method is private API that reflect internal implementation details of Time and Time::Span.
|
Actually, I believe the |
Use case: custom extensions to the Time API need a direct way to extract essential information out of a If Yes, it directly exposes the internal representation, but that isn't bad by itself. I agree that |
Who says we don't change the epoch later? And then because this is public API, |
It's the epoch of the ISO 8601 calendar. We can change the internal representation (including epoch) however we like, but the calendar epoch won't change unless we change the calendar.
With the current implementation, |
You don't expose any use case for them to be exposed either. Time extensions that would run slower isn't a use case. It's an hypothetical case.
No, this is exactly what we want: this is an internal value, don't use it, or use at your own risk, because it will break at the most unexpected time. We don't even need |
They don't exist yet. But there are enough features missing from the stdlib implementation (and shouldn't be needed there) that sooner or later there will be third party extensions. You can call it hypothetical, but that's a very realistic use case. Yes, Let's take a look at Described in different words: The only argument against I still think it makes sense to have |
I'm not sure about this. Without a use case it's hard to approve this PR. I think converting a Time from/to unix seconds is good enough. I can't see why the numbers of seconds since 01-01-01 is important (given that we have a "standard" measure against the unix epoch). |
If we add nanosecond precision to the UNIX constructor it might be fine. |
Closing stale PR. |
Time#total_seconds
was a protected method, but it can be useful outside ofTime
namespace, for example to implement custom extensions to the Time API.This method directly exposes an implementation detail, but it doesn't depend on the implementation and would be useful even if the implementation was changed. It supplements the already existing constructor
Time.new(seconds, nanoseconds)
which acceptstotal_seconds
since epoch as argument.I don't think
Time#offset_seconds
needs to be exposed since it can easily be duplicated as sum of#total_seconds
and#offset
. Instead I changed visibility toprivate
because it doesn't need to be exposed in the namespace (and isn't even used).See also #5374 (probably fixes that).