Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use Time for pointStart #264

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/lazy_high_charts/options_key_filter.rb
Expand Up @@ -9,7 +9,7 @@ module OptionsKeyFilter
FILTER_MAP = {
:data => [:format_data],
:pointInterval => [:milliseconds],
:pointStart => [:date_to_js_code]
:pointStart => [:start_point_to_js_code]
}

class << self
Expand All @@ -35,8 +35,9 @@ def milliseconds value
value * 1_000
end

def date_to_js_code date
"Date.UTC(#{date.year}, #{date.month - 1}, #{date.day})".js_code
def start_point_to_js_code start_point
time = start_point.to_time
"Date.UTC(#{time.year}, #{time.month - 1}, #{time.day}, #{time.hour}, #{time.min}, #{time.sec})".js_code
end

def format_data(data)
Expand Down
4 changes: 2 additions & 2 deletions spec/lazy_high_charts_spec.rb
Expand Up @@ -100,8 +100,8 @@
f.options[:rangeSelector] = {:selected => 1};
f.series(:type => "spline",
:name => "Historias",
:pointInterval => (1.day.to_i * 1000),
:pointStart => (Time.now.to_i * 1000),
:pointInterval => 1.day.to_i,
:pointStart => Time.now,
:data => [0, 1, 2, 3, 5, 6, 0, 7]
)
}
Expand Down
33 changes: 25 additions & 8 deletions spec/options_key_filter_spec.rb
Expand Up @@ -7,17 +7,34 @@
end

describe "filters :pointStart from a Date to a JavaScript compatible string" do
before(:each) do
hash = LazyHighCharts::OptionsKeyFilter.filter(pointStart: Date.new(2012, 9, 13))
@value = hash[:pointStart]
end
context 'with Date' do
before(:each) do
hash = LazyHighCharts::OptionsKeyFilter.filter(pointStart: Date.new(2012, 9, 13))
@value = hash[:pointStart]
end

it "should be the correct string" do
expect(@value).to eq("Date.UTC(2012, 8, 13, 0, 0, 0)")
end

it "should be the correct string" do
expect(@value).to eq("Date.UTC(2012, 8, 13)")
it "should be js_code" do
expect(@value.js_code).to be_truthy
end
end

it "should be js_code" do
expect(@value.js_code).to be_truthy
context 'with Time' do
before(:each) do
hash = LazyHighCharts::OptionsKeyFilter.filter(pointStart: Time.new(2012, 9, 13, 14, 43, 21))
@value = hash[:pointStart]
end

it "should be the correct string" do
expect(@value).to eq("Date.UTC(2012, 8, 13, 14, 43, 21)")
end

it "should be js_code" do
expect(@value.js_code).to be_truthy
end
end
end

Expand Down