[Feature][ActiveSupport::Duration] to_years, to_months, to_days, etc

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

[Feature][ActiveSupport::Duration] to_years, to_months, to_days, etc

Jason York
Hi! Would it be valuable to add some convenience methods to Duration to convert the value to years, months, days?

Ex:

1.week.to_days
=> 7

3.days.to_weeks
=> 0.429

40.hours.to_days
=> 1.67

I wanted to check here before I work on a PR.

Thanks!

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature][ActiveSupport::Duration] to_years, to_months, to_days, etc

Josh Brody
`1.week.days` is what you're looking for. I don't think an alias would be necessarily bad, though. It's similarly done elsewhere.

On Thu, Mar 5, 2020 at 5:58 PM Jason York <[hidden email]> wrote:
Hi! Would it be valuable to add some convenience methods to Duration to convert the value to years, months, days?

Ex:

1.week.to_days
=> 7

3.days.to_weeks
=> 0.429

40.hours.to_days
=> 1.67

I wanted to check here before I work on a PR.

Thanks!

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAHK71zfcEwcr%2BJxXqAE9fdam9j7vMK97AGPSvZNj8WX-t_%2BvqQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature][ActiveSupport::Duration] to_years, to_months, to_days, etc

Phillip Getto
I think 1.week.days does not yield the desired result. It is the equivalent of 1.week.to_i.days or 604800 days. The other time period name helper methods would produce analogous results.

On Thursday, March 5, 2020 at 9:04:23 PM UTC-5, Josh Brody wrote:
`1.week.days` is what you're looking for. I don't think an alias would be necessarily bad, though. It's similarly done elsewhere.

On Thu, Mar 5, 2020 at 5:58 PM Jason York <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="CKlsuIVJCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jaso...@...> wrote:
Hi! Would it be valuable to add some convenience methods to Duration to convert the value to years, months, days?

Ex:

1.week.to_days
=> 7

3.days.to_weeks
=> 0.429

40.hours.to_days
=> 1.67

I wanted to check here before I work on a PR.

Thanks!

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="CKlsuIVJCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/1d4b4309-7715-441b-a283-b1703f7dc517%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature][ActiveSupport::Duration] to_years, to_months, to_days, etc

Jason York
Phillip is correct

1.week.days
=> 604800 days


On Friday, March 6, 2020 at 8:03:13 AM UTC-6, Phillip Getto wrote:
I think 1.week.days does not yield the desired result. It is the equivalent of 1.week.to_i.days or 604800 days. The other time period name helper methods would produce analogous results.

On Thursday, March 5, 2020 at 9:04:23 PM UTC-5, Josh Brody wrote:
`1.week.days` is what you're looking for. I don't think an alias would be necessarily bad, though. It's similarly done elsewhere.

On Thu, Mar 5, 2020 at 5:58 PM Jason York <[hidden email]> wrote:
Hi! Would it be valuable to add some convenience methods to Duration to convert the value to years, months, days?

Ex:

1.week.to_days
=> 7

3.days.to_weeks
=> 0.429

40.hours.to_days
=> 1.67

I wanted to check here before I work on a PR.

Thanks!

--
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 view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/5387f55e-341a-4b02-a24c-3e8d55f1c0ff%40googlegroups.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/43c70ecb-9f74-478d-9cf4-86b9b8dfe2e2%40googlegroups.com.