Class: XlsFunction::Evaluators::Functions::TimeFn
Constant Summary
collapse
- ARG_LIMIT =
32_767
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
#eval ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/xls_function/evaluators/functions/time.rb', line 15
def eval
return ::XlsFunction::ErrorValue.num!(out_of_range) unless validate_args
adjusted = ::XlsFunction::Converters::TimeConverter.adjust_elapsed_time(hour_i, minute_i, second_i)
time = Time.new(Time.now.year, nil, nil, adjusted[:hour], adjusted[:minute], adjusted[:second])
time.to_serial(except_date: true)
end
|
#hour_i ⇒ Object
35
36
37
|
# File 'lib/xls_function/evaluators/functions/time.rb', line 35
def hour_i
@hour_i ||= hour.to_i
end
|
#minute_i ⇒ Object
39
40
41
|
# File 'lib/xls_function/evaluators/functions/time.rb', line 39
def minute_i
@minute_i ||= minute.to_i
end
|
#out_of_range ⇒ Object
47
48
49
50
|
# File 'lib/xls_function/evaluators/functions/time.rb', line 47
def out_of_range
message = error_message(:out_of_range, value: "#{hour}, #{minute}, #{second}")
class_info(message)
end
|
#second_i ⇒ Object
43
44
45
|
# File 'lib/xls_function/evaluators/functions/time.rb', line 43
def second_i
@second_i ||= second.to_i
end
|
#validate_args ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/xls_function/evaluators/functions/time.rb', line 24
def validate_args
return false if hour_i > ARG_LIMIT || minute_i > ARG_LIMIT || second_i > ARG_LIMIT
hour_sec = hour_i * 60 * 60
minute_sec = minute_i * 60
return false if (hour_sec + minute_sec + second_i).negative?
true
end
|