Skip to content

Commit

Permalink
Modify code examples in README to conform to PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanss committed Aug 26, 2014
1 parent 07dc6c8 commit fe877d6
Showing 1 changed file with 29 additions and 35 deletions.
64 changes: 29 additions & 35 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ Example Usage
>>> import holidays
>>> us_holidays = holidays.US() # or holidays.UnitedStates()
>>> date(2014,1,1) in us_holidays
>>> date(2014, 1, 1) in us_holidays
True
>>> date(2014,1,2) in us_holidays
>>> date(2014, 1, 2) in us_holidays
False
>>> us_holidays[date(2014,1,1)]
>>> us_holidays[date(2014, 1, 1)]
"New Year's Day"
>>> '2014-01-01' in us_holidays
True
>>> '1/1/2014' in us_holidays
True
>>>1388597445 in us_holidays # Unix timestamp
>>> 1388597445 in us_holidays # Unix timestamp
True
Expand Down Expand Up @@ -94,9 +94,9 @@ More Examples
# Simplest example possible
>>> import holidays
>>> date(2014,1,1) in holidays.US()
>>> date(2014, 1, 1) in holidays.US()
True
>> date(2014,1,2) in holidays.US()
>> date(2014, 1, 2) in holidays.US()
False
# But this is not efficient because it is initializing a new Holiday object
Expand All @@ -105,9 +105,9 @@ More Examples
# It is more efficient to create the object only once
>>> us_holidays = holidays.US()
>>> date(2014,1,1) in us_holidays
>>> date(2014, 1, 1) in us_holidays
True
>> date(2014,1,2) in us_holidays
>> date(2014, 1, 2) in us_holidays
False
# Each country has two class names that can be called--a full name
Expand All @@ -131,44 +131,44 @@ More Examples
# Because by default the `expand` param is True the Holiday object will add
# holidays from other years as they are required.
>>> date(2013,1,1) in us_holidays
>>> date(2013, 1, 1) in us_holidays
True
>>> us_holidays.years
set([2013,2014])
set([2013, 2014])
>>> len(us_holidays)
20
# If we change the `expand` param to False the Holiday object will no longer
# add holidays from new years
>>> us_holidays.expand = False
>>> date(2012,1,1) in us_holidays
>>> date(2012, 1, 1) in us_holidays
False
>>> us.holidays.expand = True
>>> date(2012,1,1) in us_holidays
>>> date(2012, 1, 1) in us_holidays
True
# January 1st, 2012 fell on a Sunday so the statutory holiday was observed
# on the 2nd. By default the `observed` param is True so the holiday list
# will include January 2nd, 2012 as a holiday.
>>> date(2012,1,1) in us_holidays
>>> date(2012, 1, 1) in us_holidays
True
>>> us_holidays[date(2012,1,1)]
>>> us_holidays[date(2012, 1, 1)]
"New Year's Eve"
>>> date(2012,1,2) in us_holidays
>>> date(2012, 1, 2) in us_holidays
True
>>> us_holidays.get(date(2012,1,2))
>>> us_holidays.get(date(2012 ,1, 2))
"New Year's Eve (Observed)"
# The `observed` and `expand` values can both be changed on the fly and the
# holiday list will be adjusted accordingly
>>> us_holidays.observed = False
>>> date(2012,1,2) in us_holidays
>>> date(2012, 1, 2) in us_holidays
False
us_holidays.observed = True
>> date(2012,1,2) in us_holidays
>> date(2012, 1, 2) in us_holidays
True
# Sometimes we may not be able to use the official federal statutory
Expand All @@ -183,16 +183,16 @@ More Examples
>>> # Populate the holiday list with the default US holidays
>>> holidays.UnitedStates._populate(self, year)
>>> # Remove Columbus Day
>>> self.pop(date(year,10,1)+relativedelta(weekday=MO(+2)), None)
>>> self.pop(date(year, 10, 1) + relativedelta(weekday=MO(+2)), None)
>>> # Add Ninja Turtle Day
>>> self[date(year,7,13)] = "Ninja Turtle Day"
>>> date(2014,10,14) in Holidays(country="US")
>>> self[date(year, 7, 13)] = "Ninja Turtle Day"
>>> date(2014, 10, 14) in Holidays(country="US")
True
>>> date(2014,10,14) in CorporateHolidays(country="US")
>>> date(2014, 10, 14) in CorporateHolidays(country="US")
False
>>> date(2014,7,13) in Holidays(country="US")
>>> date(2014, 7, 13) in Holidays(country="US")
False
>>> date(2014,7,13) in CorporateHolidays(country="US")
>>> date(2014 ,7, 13) in CorporateHolidays(country="US")
True
# We can also inherit from the HolidayBase class which has an empty
Expand All @@ -202,8 +202,8 @@ More Examples
>>> class NewCountryHolidays(holidays.HolidayBase):
>>> def _populate(self, year):
>>> self[date(year,1,2)] = "Some Federal Holiday"
>>> self[date(year,2,3)] = "Another Federal Holiday"
>>> self[date(year, 1, 2)] = "Some Federal Holiday"
>>> self[date(year, 2, 3)] = "Another Federal Holiday"
>>> hdays = NewCountryHolidays()
# We can also include prov/state specific holidays in our new class.
Expand All @@ -213,11 +213,11 @@ More Examples
>>> # Set default prov if not provided
>>> if self.prov == None:
>>> self.prov = 'XX'
>>> self[date(year,1,2)] = "Some Federal Holiday"
>>> self[date(year, 1, 2)] = "Some Federal Holiday"
>>> if self.prov == 'XX':
>>> self[date(year,2,3)] = "Special XX province-only holiday"
>>> self[date(year, 2, 3)] = "Special XX province-only holiday"
>>> if self.prov == 'YY':
>>> self[date(year,3,4)] = "Special YY province-only holiday"
>>> self[date(year, 3, 4)] = "Special YY province-only holiday"
>>> hdays = NewCountryHolidays()
>>> hdays = NewCountryHolidays(prov='XX')
Expand Down Expand Up @@ -251,12 +251,6 @@ Coverage
$ pip install coverage
$ coverage run --omit=*site-packages* tests.py
$ coverage report
Name Stmts Miss Cover
------------------------------
holidays 229 0 100%
tests 483 0 100%
------------------------------
TOTAL 712 0 100%
Contributions
Expand Down

0 comments on commit fe877d6

Please sign in to comment.