diff --git a/lib/pact_broker/api/renderers/html_pact_renderer.rb b/lib/pact_broker/api/renderers/html_pact_renderer.rb
index 89713262a..81870d474 100644
--- a/lib/pact_broker/api/renderers/html_pact_renderer.rb
+++ b/lib/pact_broker/api/renderers/html_pact_renderer.rb
@@ -57,8 +57,8 @@ def pact_metadata
#{@pact.consumer_version_number}#{tags}
- Date published:
- #{published_date}
+ Date published:
+ #{published_date_in_words}
View in API Browser
@@ -108,6 +108,10 @@ def published_date
@pact.created_at.to_time.localtime.to_datetime.strftime("%a %d %b %Y, %l:%M%P %:z")
end
+ def published_date_in_words
+ PactBroker::DateHelper.distance_of_time_in_words(@pact.created_at.to_time, DateTime.now) + " ago"
+ end
+
def json_url
PactBroker::Api::PactBrokerUrls.hal_browser_url pact_url
end
diff --git a/pact_broker.gemspec b/pact_broker.gemspec
index c4c90b0df..5d9459815 100644
--- a/pact_broker.gemspec
+++ b/pact_broker.gemspec
@@ -52,4 +52,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'pg', '~>0.21'
gem.add_development_dependency 'conventional-changelog', '~>1.3'
gem.add_development_dependency 'bump', '~> 0.5'
+ gem.add_development_dependency 'timecop', '~> 0.9'
end
diff --git a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
index 0d1695f17..c30635be9 100644
--- a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
+++ b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'pact_broker/api/renderers/html_pact_renderer'
+require 'timecop'
module PactBroker
module Api
@@ -10,10 +11,13 @@ module Renderers
ENV['BACKUP_TZ'] = ENV['TZ']
ENV['TZ'] = "Australia/Melbourne"
PactBroker.configuration.enable_public_badge_access = true
+
+ Timecop.freeze(created_at + 3)
end
after do
ENV['TZ'] = ENV['BACKUP_TZ']
+ Timecop.return
end
let(:consumer) { double('consumer', name: 'Consumer')}
@@ -47,6 +51,7 @@ module Renderers
expect(subject).to match /.*Some Provider/
expect(subject).to include("Date published:")
expect(subject).to include("Thu 27 Feb 2014, 11:00am +11:00")
+ expect(subject).to include("3 days ago")
expect(subject).to match /title.*Pact between Consumer and Provider/
expect(subject).to match /prod, master/
end