Class: DateOperations
- Inherits:
-
Object
- Object
- DateOperations
- Defined in:
- lib/dateoperations.rb,
lib/dateoperations/version.rb
Overview
0.1.1 - Umzug des Repositories zu Codeberg und Aktualisierung aller Homepage-URLs 0.1.0 - Anhebung der Ruby-Mindestversion auf >= 3.4.0, Aktualisierung des holidays-Gems und Code-Refactoring
Constant Summary collapse
- VERSION =
'0.1.1'
Class Attribute Summary collapse
-
.country ⇒ Object
Switches to the calendar of the respective country: - :de = Germany - :us = USA - ...
Class Method Summary collapse
-
.business_days_between(start_date, end_date) ⇒ Object
Returns an array with dates for the business days (week days (Monday to Friday) without holidays).
-
.holiday?(date) ⇒ Boolean
Checks whether a given date is a holiday based on the calendar for the respective country.
-
.number_of_business_days_between(start_date, end_date) ⇒ Object
Returns the number of business days (week days (Monday to Friday) without holidays).
-
.number_of_week_days_between(start_date, end_date) ⇒ Object
returns the number of week days (Monday to Friday) between a given start and end date.
-
.week_days_between(start_date, end_date) ⇒ Object
Returns an array with dates for the week days (Monday to Friday) between a given start and end date.
-
.weekend?(date) ⇒ Boolean
Checks whether a given date is a weekend (Saturday, Sunday).
Class Attribute Details
.country ⇒ Object
Switches to the calendar of the respective country:
- :de = Germany
- :us = USA
- ...
19 20 21 |
# File 'lib/dateoperations.rb', line 19 def country @country end |
Class Method Details
.business_days_between(start_date, end_date) ⇒ Object
Returns an array with dates for the business days (week days (Monday to Friday) without holidays). between a given start and end date.
36 37 38 39 |
# File 'lib/dateoperations.rb', line 36 def self.business_days_between(start_date, end_date) week_days = week_days_between(start_date, end_date) week_days.reject { |b| holiday?(b) } end |
.holiday?(date) ⇒ Boolean
Checks whether a given date is a holiday based on the calendar for the respective country.
54 55 56 |
# File 'lib/dateoperations.rb', line 54 def self.holiday?(date) Holidays.on(date, DateOperations.country, :informal).any? end |
.number_of_business_days_between(start_date, end_date) ⇒ Object
Returns the number of business days (week days (Monday to Friday) without holidays). between a given start and end date.
43 44 45 46 |
# File 'lib/dateoperations.rb', line 43 def self.number_of_business_days_between(start_date, end_date) business_days = business_days_between(start_date, end_date) business_days.length end |
.number_of_week_days_between(start_date, end_date) ⇒ Object
returns the number of week days (Monday to Friday) between a given start and end date.
29 30 31 32 |
# File 'lib/dateoperations.rb', line 29 def self.number_of_week_days_between(start_date, end_date) week_days = week_days_between(start_date, end_date) week_days.length end |
.week_days_between(start_date, end_date) ⇒ Object
Returns an array with dates for the week days (Monday to Friday) between a given start and end date.
23 24 25 26 |
# File 'lib/dateoperations.rb', line 23 def self.week_days_between(start_date, end_date) week_day_nbrs = (1..5) (start_date..end_date).select { |w| week_day_nbrs.include?(w.wday) } end |
.weekend?(date) ⇒ Boolean
Checks whether a given date is a weekend (Saturday, Sunday).
49 50 51 |
# File 'lib/dateoperations.rb', line 49 def self.weekend?(date) date.saturday? || date.sunday? end |