Skip to content
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

Add ISO code based constructor #257

Closed
swidz opened this issue Dec 21, 2017 · 8 comments · Fixed by #280
Closed

Add ISO code based constructor #257

swidz opened this issue Dec 21, 2017 · 8 comments · Fixed by #280
Projects

Comments

@swidz
Copy link

swidz commented Dec 21, 2017

It would be nice to have a constructor based on country ISO2 codes e.g. PL = Poland, FR = France etc.
This should be fairly easy for countries with no state, county specific holidays.

For USA it could be done by passing country + state code. State value would be skipped for other cases countries .

Not sure how counties are coded, nor if there exist any standard.
Perhaps a geonames admin code is a good start? www.geonames.org

@Natim
Copy link
Contributor

Natim commented Dec 21, 2017

Yeah I did this kind of table like that lately: https://github.com/Natim/Diggory/blob/master/diggory/calendar/__init__.py#L27

@swidz
Copy link
Author

swidz commented Dec 26, 2017

I see there is IsoRegistry class and European calendar classes are decorated with iso_register(iso_code).

from datetime import date
from workalendar.registry import *
from workalendar.europe import *

calendar = registry.get_calendar_class('PL')
cal = calendar()
print(cal.holidays(2012))

Am I using it is a right way?
Why only Europe? Is this work in progress? I could contribute. Does it require only to add the decorator with proper ISO coding and the name class attribute?

@swidz
Copy link
Author

swidz commented Dec 27, 2017

Manual registration using ISO-3166 and ISO-3166-2 codes for non European calendars:

#USA
registry.register('US', UnitedStates)
registry.register('US-AL', Alabama)
#registry.register('US-AL', AlabamaBaldwinCounty)
#registry.register('US-AL', AlabamaMobileCounty) 
#registry.register('US-AL', AlabamaPerryCounty)
registry.register('US-AK', Alaska)
registry.register('US-AZ', Arizona)
registry.register('US-AR', Arkansas)
registry.register('US-CA', California)
registry.register('US-CO', Colorado)
registry.register('US-CT', Connecticut)
registry.register('US-DE', Delaware)
registry.register('US-DC', DistrictOfColumbia)
registry.register('US-FL', Florida)
registry.register('US-GA', Georgia)
registry.register('US-HI', Hawaii)
registry.register('US-ID', Idaho)
registry.register('US-IL', Illinois)
registry.register('US-IN', Indiana)
registry.register('US-IA', Iowa)
registry.register('US-KS', Kansas)
registry.register('US-KY', Kentucky)
registry.register('US-LA', Louisiana)
registry.register('US-ME', Maine)
registry.register('US-MD', Maryland)
registry.register('US-MA', Massachusetts)
registry.register('US-MI', Michigan)
registry.register('US-MN', Minnesota)
registry.register('US-MS', Mississippi)
registry.register('US-MO', Missouri)
registry.register('US-MT', Montana)
registry.register('US-NE', Nebraska)
registry.register('US-NV', Nevada)
registry.register('US-NH', NewHampshire)
registry.register('US-NJ', NewJersey)
registry.register('US-NM', NewMexico)
registry.register('US-NY', NewYork)
registry.register('US-NC', NorthCarolina)
registry.register('US-ND', NorthDakota)
registry.register('US-OH', Ohio)
registry.register('US-OK', Oklahoma)
registry.register('US-OR', Oregon)
registry.register('US-PA', Pennsylvania)
registry.register('US-RI', RhodeIsland)
registry.register('US-SC', SouthCarolina)
registry.register('US-SD', SouthDakota)
registry.register('US-TN', Tennessee)
#registry.register('US-TX', TexasBase)
registry.register('US-TX', Texas)
registry.register('US-UT', Utah)
registry.register('US-VT', Vermont)
registry.register('US-VA', Virginia)
registry.register('US-WA', Washington)
registry.register('US-WV', WestVirginia)
registry.register('US-WI', Wisconsin)
registry.register('US-WY', Wyoming)

#America
registry.register('BR', Brazil)
registry.register('BR-AC', BrazilAcre)
registry.register('BR-AL', BrazilAlagoas)
registry.register('BR-AP', BrazilAmapa)
registry.register('BR-AM', BrazilAmazonas)
registry.register('BR-BA', BrazilBahia)
registry.register('BR-CE', BrazilCeara)
#registry.register('BR', BrazilDistritoFederal)
registry.register('BR-ES', BrazilEspiritoSanto)
registry.register('BR-GO', BrazilGoias)
registry.register('BR-MA', BrazilMaranhao)
registry.register('BR-MT', BrazilMatoGrosso)
registry.register('BR-MS', BrazilMatoGrossoDoSul)
registry.register('BR-PA', BrazilPara)
registry.register('BR-PB', BrazilParaiba)
registry.register('BR-PE', BrazilPernambuco)
registry.register('BR-PI', BrazilPiaui)
registry.register('BR-RJ', BrazilRioDeJaneiro)
registry.register('BR-RN', BrazilRioGrandeDoNorte)
registry.register('BR-RS', BrazilRioGrandeDoSul)
registry.register('BR-RO', BrazilRondonia)
registry.register('BR-RR', BrazilRoraima)
registry.register('BR-SC', BrazilSantaCatarina)
registry.register('BR-SP', BrazilSaoPauloState)
#registry.register('BR-SP', BrazilSaoPauloCity)
registry.register('BR-SE', BrazilSergipe)
registry.register('BR-TO', BrazilTocantins)
#registry.register('BR', BrazilVitoriaCity)
#registry.register('BR', BrazilVilaVelhaCity)
#registry.register('BR', BrazilCariacicaCity)
#registry.register('BR', BrazilGuarapariCity)
#registry.register('BR', BrazilSerraCity)
#registry.register('BR', BrazilBankCalendar)

registry.register('CL', Chile)
registry.register('CO', Colombia)
registry.register('MX', Mexico)
registry.register('PA', Panama)

#Afrika
registry.register('DZ', Algeria)
registry.register('BJ', Benin)
registry.register('CI', IvoryCoast)
registry.register('MG', Madagascar)
registry.register('ST', SaoTomeAndPrincipe)
registry.register('ZA', SouthAfrica)

#Asia
registry.register('HK', HongKong)
registry.register('JP', Japan)
registry.register('MY', Malaysia) 
registry.register('QA', Qatar)
registry.register('SG', Singapore) 
registry.register('KR', SouthKorea) 
registry.register('TW', Taiwan)

#Oceania
registry.register('AU', Australia)
registry.register('AU-ACT', AustralianCapitalTerritory)
registry.register('AU-NSW', NewSouthWales)
registry.register('AU-NT', NorthernTerritory)
registry.register('AU-QLD', Queensland)
registry.register('AU-SA', SouthAustralia)
registry.register('AU-TAS', Tasmania)
#registry.register('AU-TAS', Hobart)
registry.register('AU-VIC', Victoria)
registry.register('AU-WA', WesternAustralia)

registry.register('MH', MarshallIslands)

#Canada
registry.register('CA', Canada)
registry.register('CA-ON', Ontario)
registry.register('CA-QC', Quebec)
registry.register('CA-BC', BritishColumbia)
registry.register('CA-AL', Alberta)
registry.register('CA-SK', Saskatchewan)
registry.register('CA-MB', Manitoba)
registry.register('CA-NB', NewBrunswick)
registry.register('CA-NS', NovaScotia)
registry.register('CA-PE', PrinceEdwardIsland)
registry.register('CA-NL', Newfoundland)
registry.register('CA-YT', Yukon)
registry.register('CA-NT', NorthwestTerritories)
registry.register('CA-NU', Nunavut)

@antvig
Copy link

antvig commented Jan 9, 2018

When will be the next release with the registry module ?
Thanks !

@brunobord
Copy link
Member

the latest to date, released yesterday, now contains the registry utility. Go for it! :o)

@antvig
Copy link

antvig commented May 31, 2018

Is there a reason why only European country are registered?

@brunobord
Copy link
Member

@antvig it might be just because I started with one continent. When I have time I'll add some more. Feel free to contribute! ;o)

@brunobord
Copy link
Member

I'm planning to work on this in the near future. stay tuned!

brunobord added a commit that referenced this issue Aug 23, 2018
brunobord added a commit that referenced this issue Aug 23, 2018
brunobord added a commit that referenced this issue Aug 23, 2018
refs #257

FYI, I've transformed the `oceania.py` into a module, for more consistency.
brunobord added a commit that referenced this issue Aug 30, 2018
brunobord added a commit that referenced this issue Aug 30, 2018
brunobord added a commit that referenced this issue Aug 30, 2018
refs #257

FYI, I've transformed the `oceania.py` into a module, for more consistency.
brunobord added a commit that referenced this issue Aug 30, 2018
brunobord added a commit that referenced this issue Aug 30, 2018
refs #257

FYI, I've transformed the `oceania.py` into a module, for more consistency.
brunobord added a commit that referenced this issue Aug 30, 2018
brunobord added a commit that referenced this issue Aug 30, 2018
refs #257

FYI, I've transformed the `oceania.py` into a module, for more consistency.
@brunobord brunobord mentioned this issue Aug 30, 2018
4 tasks
@brunobord brunobord added this to Working in Workalendar Aug 30, 2018
@brunobord brunobord moved this from Working to Done in Workalendar Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Workalendar
  
Done/Closed/Published
Development

Successfully merging a pull request may close this issue.

4 participants