Skip to content

Commit

Permalink
Merge pull request #14296 from durandom/ansible_events_timestamp
Browse files Browse the repository at this point in the history
always pass valid date format
  • Loading branch information
blomquisg authored Mar 20, 2017
2 parents c9cf152 + f068c83 commit bd25694
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def poll
private

def filter
timestamp = @last_activity ? Time.zone.parse(@last_activity.timestamp.to_s) : 1.minute.ago
{
:order_by => 'timestamp',
:timestamp__gt => @last_activity ? @last_activity.timestamp : 1.minute.ago.to_s(:db)
:timestamp__gt => timestamp.to_s(:db)
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,19 @@
end
end
end

context ".filter" do
it "converts timestamp to correct timeformat" do
# It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]
timestamps = {
'2016-01-01 01:00:00' => '2016-01-01 01:00:00',
'2017-03-10 19%3A31%3A26' => '2017-03-10 00:00:00',
Time.zone.parse('1975-12-31 01:01:01') => '1975-12-31 01:01:01',
}
timestamps.each do |input, converted|
subject.instance_variable_set(:@last_activity, OpenStruct.new(:timestamp => input))
expect(subject.send(:filter)[:timestamp__gt]).to eq(converted)
end
end
end
end

0 comments on commit bd25694

Please sign in to comment.