Module: LibTAD::Client::DateCalculatorService
- Included in:
- LibTAD::Client
- Defined in:
- lib/services/date_calculator.rb
Overview
Date Calculator API.
Instance Method Summary collapse
-
#add_days(place_id: nil, country: nil, state: nil, start_date:, days:, including: nil, filter: nil, repeat: nil, lang: nil) ⇒ ::LibTAD::Places::Geo, Array<::LibTAD::DateCalculator::Period>
The Businessdate service can be used to find a business date from a specified number of days.
-
#get_duration(place_id: nil, country: nil, state: nil, start_date:, end_date:, including: nil, filter: nil, include_last_date: nil, lang: nil) ⇒ ::LibTAD::Places::Geo, ::LibTAD::DateCalculator::Period
The Businessduration service can be used to calculate the number of business days between a specified start date and end date.
-
#subtract_days(place_id: nil, country: nil, state: nil, start_date:, days:, including: nil, filter: nil, repeat: nil, lang: nil) ⇒ ::LibTAD::Places::Geo, Array<::LibTAD::DateCalculator::Period>
The Businessdate service can be used to find a business date from a specified number of days.
Instance Method Details
#add_days(place_id: nil, country: nil, state: nil, start_date:, days:, including: nil, filter: nil, repeat: nil, lang: nil) ⇒ ::LibTAD::Places::Geo, Array<::LibTAD::DateCalculator::Period>
The Businessdate service can be used to find a business date from a specified number of days. By default the result will be filtered on excluding weekends and public holidays, but you can specify a custom filter to modify this.
Either place_id or country is required.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/services/date_calculator.rb', line 22 def add_days( place_id: nil, country: nil, state: nil, start_date:, days:, including: nil, filter: nil, repeat: nil, lang: nil ) args = { placeid: place_id, country: country, state: state, startdt: if start_date.methods.include?(:to_iso8601) then start_date.to_iso8601 else start_date end, days: days, include: including, filter: (filter unless ![*filter].all? { |e| ::LibTAD::DateCalculator::BUSINESS_DAYS_FILTER.include?(e) }), repeat: repeat, lang: lang }.compact call_business_date(args, 'add') end |
#get_duration(place_id: nil, country: nil, state: nil, start_date:, end_date:, including: nil, filter: nil, include_last_date: nil, lang: nil) ⇒ ::LibTAD::Places::Geo, ::LibTAD::DateCalculator::Period
The Businessduration service can be used to calculate the number of business days between a specified start date and end date.
When you query the Businessduration service with a placeid or a country, a start date and an end date the service will return the number of business days in that date range by excluding public holidays and weekends. Furthermore, you can apply additional filters such as individual days and whether or not the calculation should include the filter result or exclude it.
Either place_id or country is required.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/services/date_calculator.rb', line 111 def get_duration( place_id: nil, country: nil, state: nil, start_date:, end_date:, including: nil, filter: nil, include_last_date: nil, lang: nil ) args = { placeid: place_id, country: country, state: state, startdt: if start_date.methods.include?(:to_iso8601) then start_date.to_iso8601 else start_date end, enddt: if end_date.methods.include?(:to_iso8601) then end_date.to_iso8601 else end_date end, include: including, filter: (filter unless ![*filter].all? { |e| ::LibTAD::DateCalculator::BUSINESS_DAYS_FILTER.include?(e) }), includelastdate: include_last_date, lang: lang }.compact response = get('businessduration', args) geo = ::LibTAD::Places::Geo.new response['geo'] unless !response.key?('geo') period = ::LibTAD::DateCalculator::Period.new response['period'] unless !response.key?('period') return geo, period end |
#subtract_days(place_id: nil, country: nil, state: nil, start_date:, days:, including: nil, filter: nil, repeat: nil, lang: nil) ⇒ ::LibTAD::Places::Geo, Array<::LibTAD::DateCalculator::Period>
The Businessdate service can be used to find a business date from a specified number of days. By default the result will be filtered on excluding weekends and public holidays, but you can specify a custom filter to modify this.
Either place_id or country is required.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/services/date_calculator.rb', line 65 def subtract_days( place_id: nil, country: nil, state: nil, start_date:, days:, including: nil, filter: nil, repeat: nil, lang: nil ) args = { placeid: place_id, country: country, state: state, startdt: if start_date.methods.include?(:to_iso8601) then start_date.to_iso8601 else start_date end, days: days, include: including, filter: (filter unless ![*filter].all? { |e| ::LibTAD::DateCalculator::BUSINESS_DAYS_FILTER.include?(e) }), repeat: repeat, lang: lang }.compact call_business_date(args, 'subtract') end |