Proposal: Add countries_zones for fetching multiple TimeZones for multiple Countries

Hey! I’m learning to hate time zones and I’m trying to fetch time zones for multiple countries. I was surprised that rails didn’t already support passing multiple country codes into #country_zones, but I guess that makes sense since country is singular. I’ve made the changes and wrote up some specs and as per the contribution guidelines I was hoping to garner some support for introducing a method which allows you to pass in multiple country codes to get all the time zones for said countries. For example: ActiveSupport::TimeZone.countries_zones(:ca, :us).count => 52

changes: Comparing main...add-countries-zone-method · kalmai/rails-source · GitHub

Thanks for your time!

May I ask what your thinking is behind this? The code is simple (which is good) and a while ago I also liked approaches like this.

What changed my mind over the years, was having to understand my own code months or even years later. If something makes writing code easier, that is great. But only if it does NOT (edit: had forgotten the “NO”, sorry) make understanding it (much) later more difficult.

I am not trying to question the intent or anything. Merely wanted to add the perspective of long-term code maintenance. Also, I will freely admit that with Rails and Ruby I am newbie. My experience is more in the Java world (if that is relevant to the discussion).

Either way, I applaud the initiative !!

How does this differ from:

[:us, :ca].each { |c| ActiveSupport::TimeZone.country_zones(c).to_a }

– H

I guess it kind of felt like a method like this should be in rails with all the helper methods out there. Maybe if I had to implement this in more than one or two projects I’d probably want to include this method in Rails even though the code is simple and easy to implement.

In regards to maintainability, I don’t really see that much confusion or difficulty maintaining this addition since it stems from the #country_zones method. I guess my confusion would come from using the singular or plural version.

I guess this helper method is just a nicety, not really too impactful or important. Either way, it was neat to figure out how I can contribute to a framework I love so much!

Dropping into a rails console, the code just yields the input array. I wanted to see what would happen even though I suspected this. ActiveSupport::TimeZone.country_zones(c) also returns an array of time zones already, so calling #to_a is not necessary. So instead of the count of time zones yielding 52, as it should, the provided code would only yield 2 if we were to slap #count on the end of it.