Getting the name of a region
samstickland opened this issue · comments
Hi,
I'm trying to use this in an application to mark Bank Holidays in a user's calendar.
In order to make this work I'm assuming I need to collect the region a user is in, and to do that I'm going to need a list of regions, converted to English names (at the very least, possibly I18n'ed names in the future).
Is there anyway to do that?
Also, there seems to be some regions I wouldn't want a user to select. For example, if gb_con (Cornwall) is selected, then this will no longer show Easter Monday in England, which is incorrect:
> Holidays.on(Date.parse('2016-03-28'), :gb_con)
=> []
> Holidays.on(Date.parse('2016-03-28'), :gb_eng)
=> [{:date=>Mon, 28 Mar 2016, :name=>"Easter Monday", :regions=>[:gb_eng, :gb_wls, :gb_eaw, :gb_nir]}]
Hi @samstickland! Sorry for the delay, had a busy week.
Currently I don't think we can give you what you seem to need. All I can give you at the moment is a list of all of the regions we have available:
Holidays.load_all
Holidays.regions # <- returns an array of all available region symbols (i.e. :gb, :us, etc)
This isn't exactly what you want but currently we don't map an English name, let alone a i18n'ed name. That'll have to be something we add.
As to your second point, the issue is that :gb
is an overall 'parent' (for lack of a better term) region. Really :gb_con
should be a sub-region of :gb_eng
, if I understand correctly (I'm American so I might have my names/regions wrong).
I'll need to think about this as well, as I can definitely see a use for it but up to this stage we haven't needed to do it. In our current nomenclature we would want to do something like :gb_eng_con
to indicate that 'Cornwall' belonged as a sub-region of :gb_eng
but I don't think our current logic will allow that.
These are a reasonable requests. I'm going to leave this open as a feature request and work on it in the near future, I think it's doable. No timeframe at this time, though.
If you have the countries gem installed then you can do something like this...
Holidays.available_regions.sort.uniq.map{|r|
ISO3166::Country[r] ? [ ISO3166::Country[r].name , r ] : nil }.compact.sort_by{|a| a[0]}
=> [["Argentina", :ar], ["Austria", :at], ["Australia", :au], .....
BTW, 'Christmas Day' does not seem to be listed as a holiday for Australia (:au).
@jlsync Hm, interesting! Unfortunately one problem is that not all of our regions are currently ISO compatible, I don't think. Since I've taken over any new regions must be and I've been correcting them as I've found issues but I would have to do an audit to figure out which ones are 'incorrect' currently. Still a good option to have, though. Thank you!
To your second point, bah! I missed this in past refactorings. I'm going to create another issue so I don't lose track of it. Thank you!
I went through the symbols and found the names for each of them and put them in a hash in this gist. (It's already slightly out of date with the latest changes to the definitions from a month ago but should be quite fast to clean it up).
A bit of feedback about things I discovered while going through the list:
Duplicates
- Isle of Man is listed as both
:im
and:gb_iom
(seems to be on purpose, not sure why) :es_v
(Valencia) and:es_vc
(Valencian Community) encode the same data as well- (Maybe in case there's ever another refactor, aliases could be supported, so a region can have multiple names and codes, but there's also a way to get a listing without duplication?)
- Localisation has somehow snuck its way in as separate symbols for a couple of countries, Belgium and Bulgaria, with the symbols
:be_fr
,:be_nl
, and:bg_bg
,:bg_en
even though they (as far as I can tell) encode exactly the same holidays.
Very detailed sub-regions and organizations
- Not a bug per se, but at least for my use cases I don't want to ask my users if they come from Northern or Southern Tasmania (
au_tas_north
andau_tas_south
) - if the level of detail you care about is only country and state, but not further down than that, then stick to only the:xx
and:xx_xx
symbols, but leave out thexx_xx_xx
- Similarly, if a user only wants geographic regions, then they manually have to leave out all the organisation symbols like
:nyse
(New York Stock Exchange),ecb_target
(European Central Bank) and similar. Some kind of categorization of the symbols, so a user of the gem could ask for e.g. 'countries', 'regions', 'sub-regions', 'organizations' separately would be nice.