Module: ApexCharts::Utils::DateTime
- Included in:
- OptionsBuilder
- Defined in:
- lib/apex_charts/utils/date_time.rb
Class Method Summary collapse
- .convert(input) ⇒ Object
- .convert_range(input) ⇒ Object
- .to_milliseconds(input) ⇒ Object
- .to_milliseconds_range(first, last) ⇒ Object
- .type(input) ⇒ Object
Class Method Details
.convert(input) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/apex_charts/utils/date_time.rb', line 10 def convert(input) case input when Time (input.to_f * 1000).round when ::DateTime, Date (input.to_time.to_f * 1000).round else if (dt = ::DateTime.iso8601(input)).iso8601 == input (dt.to_time.to_f * 1000).round elsif (d = Date.iso8601(input)).iso8601 == input (d.to_time.to_f * 1000).round end end rescue StandardError input end |
.convert_range(input) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/apex_charts/utils/date_time.rb', line 27 def convert_range(input) input_first, input_last = input.first, input.last case input_first when Time to_milliseconds_range(input_first, input_last) when ::DateTime, Date to_milliseconds_range(input_first.to_time, input_last.to_time) else if (datetime = ::DateTime.iso8601(input_first)).iso8601 == input_first to_milliseconds_range(datetime.to_time, ::DateTime.iso8601(input_last).to_time) elsif (date = Date.iso8601(input.first)).iso8601 == input_first to_milliseconds_range(date.to_time, ::Date.iso8601(input_last).to_time) end end rescue StandardError input end |
.to_milliseconds(input) ⇒ Object
45 46 47 |
# File 'lib/apex_charts/utils/date_time.rb', line 45 def to_milliseconds(input) (input.to_f * 1000).round end |
.to_milliseconds_range(first, last) ⇒ Object
49 50 51 |
# File 'lib/apex_charts/utils/date_time.rb', line 49 def to_milliseconds_range(first, last) to_milliseconds(first)..to_milliseconds(last) end |
.type(input) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/apex_charts/utils/date_time.rb', line 53 def type(input) case input when Time, ::DateTime, Date 'datetime' else if [ ::DateTime.iso8601(input).iso8601, Date.iso8601(input).iso8601 ].include? input 'datetime' end end rescue StandardError nil end |