lib/base/summarizer.rb in wvanbergen-request-log-analyzer-0.2.2 vs lib/base/summarizer.rb in wvanbergen-request-log-analyzer-0.3.0

- old
+ new

@@ -65,7 +65,21 @@ # <tt>min_count</tt> Values which fall below this amount are not returned (default @blocker_duration). def sort_errors_by(field, min_count = nil) errors = min_count.nil? ? @errors.to_a : @errors.delete_if { |k, v| v[:count] < min_count}.to_a errors.sort { |a, b| a[1][field.to_sym] <=> b[1][field.to_sym] } end + + # Compare date strings fast + # Assumes date formats: "2008-07-14 12:11:20" or alike. + # <tt>first_date</tt> The first date string + # <tt>second_date</tt> The second date string + # Returns -1 if first_date < second_date, nil if equal + # and 1 if first_date > second_date (<=>) + def hamburger_compare_string_dates first_date, second_date + return nil if first_date.nil? || second_date.nil? + + first_date.gsub(/[^0-9|\s]/,'').to_i \ + <=> \ + second_date.gsub(/[^0-9|\s]/,'').to_i + end end end