Module: LibTAD::Client::DateCalculatorService

Included in:
LibTAD::Client
Defined in:
lib/services/date_calculator.rb

Overview

Date Calculator API.

Instance Method Summary collapse

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.

Parameters:

  • place_id (String) (defaults to: nil)

    Specify the ID of the location you would like to calculate the business date. The ID is used to find what holidays are applicable for the given place so the calculation can exclude or include those results.

  • country (String) (defaults to: nil)

    Specify the country for which you would like to calculate the business date.

  • state (String) (defaults to: nil)

    Specify the state in the given country you want to calculate the business date.

  • start_date (::LibTAD::TADTime::TADDateTime or String)

    Specify the start date. Takes a TADDateTime object or a ISO 8601 date string.

  • days (Integer)

    Specify an amount or a list of amounts of business days to count.

  • including (Boolean) (defaults to: nil)

    Specify whether the result should be calculated by including instead of excluding the days.

  • filter (Symbol) (defaults to: nil)

    Specify a type or a list of types to filter by.

  • repeat (Integer) (defaults to: nil)

    Set how many times the calculation should be repeated.

  • lang (String) (defaults to: nil)

    The preferred language for the texts.

Returns:

See Also:



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.

Parameters:

  • place_id (String) (defaults to: nil)

    Specify the ID of the location you would like to calculate the business duration. The ID is used to find what holidays are applicable for the given place so the calculation can exclude or include those results.

  • country (String) (defaults to: nil)

    Specify the country for which you would like to calculate the business date.

  • state (String) (defaults to: nil)

    Specify the state in the given country you want to calculate the business date.

  • start_date (::LibTAD::TADTime::TADDateTime or String)

    Specify the start date. Takes a TADDateTime object or a ISO 8601 date string.

  • end_date (::LibTAD::TADTime::TADDateTime or String)

    Specify the end date. Takes a TADDateTime object or a ISO 8601 date string.

  • including (Boolean) (defaults to: nil)

    Specify whether the result should be calculated by including instead of excluding the days.

  • filter (Symbol) (defaults to: nil)

    Specify a type or a list of types to filter by.

  • include_last_date (Boolean) (defaults to: nil)

    Whether or not the last date should be counted in the result.

  • lang (String) (defaults to: nil)

    The preferred language for the texts.

Returns:

See Also:



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.

Parameters:

  • place_id (String) (defaults to: nil)

    Specify the ID of the location you would like to calculate the business date. The ID is used to find what holidays are applicable for the given place so the calculation can exclude or include those results.

  • country (String) (defaults to: nil)

    Specify the country for which you would like to calculate the business date.

  • state (String) (defaults to: nil)

    Specify the state in the given country you want to calculate the business date.

  • start_date (::LibTAD::TADTime::TADDateTime or String)

    Specify the start date. Takes a TADDateTime object or a ISO 8601 date string.

  • days (Integer)

    Specify an amount or a list of amounts of business days to count.

  • including (Boolean) (defaults to: nil)

    Specify whether the result should be calculated by including instead of excluding the days.

  • filter (Symbol) (defaults to: nil)

    Specify a type or a list of types to filter by.

  • repeat (Integer) (defaults to: nil)

    Set how many times the calculation should be repeated.

  • lang (String) (defaults to: nil)

    The preferred language for the texts.

Returns:

See Also:



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