[Feature] Numeric#milliseconds to complement #minutes, #hours, #days, etc.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Feature] Numeric#milliseconds to complement #minutes, #hours, #days, etc.

Tim Rogers
ActiveSupport monkeypatches `Numeric` to add time-related functionality (see activesupport/lib/active_support/core_ext/numeric/time.rb), giving you some nice sugar for working with time, e.g.:

1.second
2.hours
3.days
4.months
5.years

At the moment, there's an `#in_milliseconds` method which converts a number of seconds to a number of milliseconds (e.g. `5.in_milliseconds == 5000`).

However, there isn't a `#milliseconds` monkeypatch. I can imagine this being useful for cases like `sleep(5.milliseconds)` or `expect(racing_car.last_repaired_at).to be_within(5.milliseconds).of(Time.zone.now)`.

I'd be willing to build this; it should be a small change.

What do people think?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Numeric#milliseconds to complement #minutes, #hours, #days, etc.

Jeremy Daer
Iā€™d use this. šŸ‘
On Wed, Apr 18, 2018 at 12:09 Tim Rogers <[hidden email]> wrote:
ActiveSupport monkeypatches `Numeric` to add time-related functionality (see activesupport/lib/active_support/core_ext/numeric/time.rb), giving you some nice sugar for working with time, e.g.:

1.second
2.hours
3.days
4.months
5.years

At the moment, there's an `#in_milliseconds` method which converts a number of seconds to a number of milliseconds (e.g. `5.in_milliseconds == 5000`).

However, there isn't a `#milliseconds` monkeypatch. I can imagine this being useful for cases like `sleep(5.milliseconds)` or `expect(racing_car.last_repaired_at).to be_within(5.milliseconds).of(Time.zone.now)`.

I'd be willing to build this; it should be a small change.

What do people think?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Numeric#milliseconds to complement #minutes, #hours, #days, etc.

Uysim Ty
In reply to this post by Tim Rogers
I support this

On Wednesday, April 18, 2018 at 11:09:48 PM UTC+7, Tim Rogers wrote:
ActiveSupport monkeypatches `Numeric` to add time-related functionality (see <a href="https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/numeric/time.rb" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frails%2Frails%2Fblob%2Fmaster%2Factivesupport%2Flib%2Factive_support%2Fcore_ext%2Fnumeric%2Ftime.rb\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHWazRe_Y4k1QWal3ScJPgXDaTgng&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frails%2Frails%2Fblob%2Fmaster%2Factivesupport%2Flib%2Factive_support%2Fcore_ext%2Fnumeric%2Ftime.rb\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHWazRe_Y4k1QWal3ScJPgXDaTgng&#39;;return true;">activesupport/lib/active_support/core_ext/numeric/time.rb), giving you some nice sugar for working with time, e.g.:

1.second
2.hours
3.days
4.months
5.years

At the moment, there's an `#in_milliseconds` method which converts a number of seconds to a number of milliseconds (e.g. `5.in_milliseconds == 5000`).

However, there isn't a `#milliseconds` monkeypatch. I can imagine this being useful for cases like `sleep(5.milliseconds)` or `expect(racing_car.last_repaired_at).to be_within(5.milliseconds).of(Time.zone.now)`.

I'd be willing to build this; it should be a small change.

What do people think?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Numeric#milliseconds to complement #minutes, #hours, #days, etc.

Greg Navis
Sounds good!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Numeric#milliseconds to complement #minutes, #hours, #days, etc.

Alberto Almagro
In reply to this post by Tim Rogers
That would be great Tim!

El miĆ©rcoles, 18 de abril de 2018, 18:09:48 (UTC+2), Tim Rogers escribiĆ³:
ActiveSupport monkeypatches `Numeric` to add time-related functionality (see <a href="https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/numeric/time.rb" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frails%2Frails%2Fblob%2Fmaster%2Factivesupport%2Flib%2Factive_support%2Fcore_ext%2Fnumeric%2Ftime.rb\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHWazRe_Y4k1QWal3ScJPgXDaTgng&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frails%2Frails%2Fblob%2Fmaster%2Factivesupport%2Flib%2Factive_support%2Fcore_ext%2Fnumeric%2Ftime.rb\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHWazRe_Y4k1QWal3ScJPgXDaTgng&#39;;return true;">activesupport/lib/active_support/core_ext/numeric/time.rb), giving you some nice sugar for working with time, e.g.:

1.second
2.hours
3.days
4.months
5.years

At the moment, there's an `#in_milliseconds` method which converts a number of seconds to a number of milliseconds (e.g. `5.in_milliseconds == 5000`).

However, there isn't a `#milliseconds` monkeypatch. I can imagine this being useful for cases like `sleep(5.milliseconds)` or `expect(racing_car.last_repaired_at).to be_within(5.milliseconds).of(Time.zone.now)`.

I'd be willing to build this; it should be a small change.

What do people think?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature] Numeric#milliseconds to complement #minutes, #hours, #days, etc.

Jake Niemiec
This might also be useful in the sense that JavaScript Date() timestamps areĀ based on a time value that is milliseconds since the unix epoch. (as opposed to seconds for server-side timestamps)

On Fri, Oct 5, 2018 at 11:20 AM Alberto Almagro <[hidden email]> wrote:
That would be great Tim!


El miĆ©rcoles, 18 de abril de 2018, 18:09:48 (UTC+2), Tim Rogers escribiĆ³:
ActiveSupport monkeypatches `Numeric` to add time-related functionality (see activesupport/lib/active_support/core_ext/numeric/time.rb), giving you some nice sugar for working with time, e.g.:

1.second
2.hours
3.days
4.months
5.years

At the moment, there's an `#in_milliseconds` method which converts a number of seconds to a number of milliseconds (e.g. `5.in_milliseconds == 5000`).

However, there isn't a `#milliseconds` monkeypatch. I can imagine this being useful for cases like `sleep(5.milliseconds)` or `expect(racing_car.last_repaired_at).to be_within(5.milliseconds).of(Time.zone.now)`.

I'd be willing to build this; it should be a small change.

What do people think?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.