Class: XlsFunction::Evaluators::Functions::DateFn

Inherits:
XlsFunction::Evaluators::FunctionEvaluator show all
Defined in:
lib/xls_function/evaluators/functions/date.rb

Instance Method Summary collapse

Methods inherited from XlsFunction::Evaluators::FunctionEvaluator

#arg_list, #before_eval, #convert_to, create, #detect_error, #error?, #error_message, #eval_arglist, #eval_or_map_eval, #evaluate, #evaluate_or_self, #initialize, #map_eval, to_h, #to_proc, to_proc, translated_description, #variant_context

Methods included from ClassDictionary

included

Methods included from ErrorDetector

#class_info, #class_name, included, #rescue_with

Methods included from ArgumentsDefinable

included

Methods included from Evaluable

#evaluate, included

Constructor Details

This class inherits a constructor from XlsFunction::Evaluators::FunctionEvaluator

Instance Method Details

#day_iObject



46
47
48
# File 'lib/xls_function/evaluators/functions/date.rb', line 46

def day_i
  @day_i ||= day.to_i
end

#day_valueObject



34
35
36
# File 'lib/xls_function/evaluators/functions/date.rb', line 34

def day_value
  day_i - 1
end

#evalObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/xls_function/evaluators/functions/date.rb', line 13

def eval
  return ::XlsFunction::ErrorValue.num!(out_of_range) if year_i >= 10_000

  date = Date.new(year_value, 1, 1)
  date >>= month_value
  date += day_value

  date_value = date.to_serial
  return ::XlsFunction::ErrorValue.num!(out_of_range) if date_value.negative?

  date_value
end

#month_iObject



42
43
44
# File 'lib/xls_function/evaluators/functions/date.rb', line 42

def month_i
  @month_i ||= month.to_i
end

#month_valueObject



30
31
32
# File 'lib/xls_function/evaluators/functions/date.rb', line 30

def month_value
  month_i - 1
end

#out_of_rangeObject



50
51
52
53
# File 'lib/xls_function/evaluators/functions/date.rb', line 50

def out_of_range
  message = error_message(:out_of_range, value: "#{year}, #{month}, #{day}")
  class_info(message)
end

#year_iObject



38
39
40
# File 'lib/xls_function/evaluators/functions/date.rb', line 38

def year_i
  @year_i ||= year.to_i
end

#year_valueObject



26
27
28
# File 'lib/xls_function/evaluators/functions/date.rb', line 26

def year_value
  year_i >= 1900 ? year_i : year_i + 1900
end