Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/split/experiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def save

if new_record?
Split.redis.sadd(:experiments, name)
Split.redis.hset(:experiment_start_times, @name, Time.now)
Split.redis.hset(:experiment_start_times, @name, Time.now.to_i)
@alternatives.reverse.each {|a| Split.redis.lpush(name, a.name)}
@goals.reverse.each {|a| Split.redis.lpush(goals_key, a)} unless @goals.nil?
else
Expand Down Expand Up @@ -157,7 +157,14 @@ def reset_winner

def start_time
t = Split.redis.hget(:experiment_start_times, @name)
Time.parse(t) if t
if t
# Check if stored time is an integer
if t =~ /^[-+]?[0-9]+$/
t = Time.at(t.to_i)
else
t = Time.parse(t)
end
end
end

def next_alternative
Expand Down
11 changes: 10 additions & 1 deletion spec/experiment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def alternative(color)
end

it "should save the start time to redis" do
experiment_start_time = Time.parse("Sat Mar 03 14:01:03")
experiment_start_time = Time.at(1372167761)
Time.stub(:now => experiment_start_time)
experiment.save

Expand All @@ -59,6 +59,15 @@ def alternative(color)
Split::Experiment.find('basket_text').algorithm.should == experiment_algorithm
end

it "should handle having a start time stored as a string" do
experiment_start_time = Time.parse("Sat Mar 03 14:01:03")
Time.stub(:now => experiment_start_time)
experiment.save
Split.redis.hset(:experiment_start_times, experiment.name, experiment_start_time)

Split::Experiment.find('basket_text').start_time.should == experiment_start_time
end

it "should handle not having a start time" do
experiment_start_time = Time.parse("Sat Mar 03 14:01:03")
Time.stub(:now => experiment_start_time)
Expand Down