Class: XlsFunction::Evaluators::Functions::DateFn
Instance Method Summary
collapse
#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
included
#class_info, #class_name, included, #rescue_with
included
Methods included from Evaluable
#evaluate, included
Instance Method Details
#day_i ⇒ Object
46
47
48
|
# File 'lib/xls_function/evaluators/functions/date.rb', line 46
def day_i
@day_i ||= day.to_i
end
|
#day_value ⇒ Object
34
35
36
|
# File 'lib/xls_function/evaluators/functions/date.rb', line 34
def day_value
day_i - 1
end
|
#eval ⇒ Object
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_i ⇒ Object
42
43
44
|
# File 'lib/xls_function/evaluators/functions/date.rb', line 42
def month_i
@month_i ||= month.to_i
end
|
#month_value ⇒ Object
30
31
32
|
# File 'lib/xls_function/evaluators/functions/date.rb', line 30
def month_value
month_i - 1
end
|
#out_of_range ⇒ Object
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_i ⇒ Object
38
39
40
|
# File 'lib/xls_function/evaluators/functions/date.rb', line 38
def year_i
@year_i ||= year.to_i
end
|
#year_value ⇒ Object
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
|