From f1bd68a8734085d101a2aea18fa2220201a6ca60 Mon Sep 17 00:00:00 2001 From: Alex Legler Date: Sat, 14 Mar 2015 16:24:34 +0100 Subject: Rework date handling --- lib/glsav1.rb | 5 ++++- lib/helpers.rb | 8 ++++++-- views/glsa/glsav1.erb | 4 ++-- views/index.erb | 2 +- views/layout.erb | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/glsav1.rb b/lib/glsav1.rb index 789de2b..0ecea87 100644 --- a/lib/glsav1.rb +++ b/lib/glsav1.rb @@ -1,3 +1,5 @@ +require 'date' + # A version 1 GLSA class GLSAv1 attr_reader :id, :title, :synopsis, :product, :date, :revised, :revision, :bugs, :access, :packages, @@ -8,9 +10,10 @@ class GLSAv1 @title = xml.xpath('/glsa/title/text()').first.content @synopsis = xml.xpath('/glsa/synopsis/text()').first.content @product = xml.xpath('/glsa/product/text()').first.content - @date = xml.xpath('/glsa/announced/text()').first.content + @date = DateTime.parse(xml.xpath('/glsa/announced/text()').first.content) @revised, @revision = xml.xpath('/glsa/revised/text()').first.content.split(': ') + @revised = DateTime.parse(@revised) @bugs = xml.xpath('/glsa/bug/text()').map {|bug_node| bug_node.content.to_i } @access = xml.xpath('/glsa/access/text()').first.content diff --git a/lib/helpers.rb b/lib/helpers.rb index 34ed17f..9a2f0f1 100644 --- a/lib/helpers.rb +++ b/lib/helpers.rb @@ -31,6 +31,10 @@ helpers do text.gsub('', '
').gsub('', '
').gsub(/ +/, ' ').chomp end + def date_format(d) + d.strftime('%B %d, %Y') + end + # Returns the comparator in the format needed for the XML def xml_comp(val) COMP_MAP[val] @@ -47,13 +51,13 @@ helpers do maker.channel.link = "https://security.gentoo.org/glsa" maker.channel.description = "This feed contains new Gentoo Linux Security Advisories. Contact security@gentoo.org with questions." maker.channel.title = "Gentoo Linux Security Advisories" - maker.channel.updated = Time.now.to_s + maker.channel.updated = items.first.revised.to_s items.each do |input_item| maker.items.new_item do |item| item.link = BASE_URL + 'glsa/' + input_item.id item.title = "GLSA %s: %s" % [input_item.id, input_item.title] - item.updated = Time.now.to_s + item.updated = input_item.revised.to_s end end end.to_s diff --git a/views/glsa/glsav1.erb b/views/glsa/glsav1.erb index f779ead..d274fa0 100644 --- a/views/glsa/glsav1.erb +++ b/views/glsa/glsav1.erb @@ -57,12 +57,12 @@

Release Date
- <%= h @glsa.date %> + <%= date_format @glsa.date %>

Latest Revision
- <%= h @glsa.revised %>: <%= h @glsa.revision %> + <%= date_format @glsa.revised %>: <%= h @glsa.revision %>

Severity diff --git a/views/index.erb b/views/index.erb index 26d8ce5..56e81ea 100644 --- a/views/index.erb +++ b/views/index.erb @@ -32,7 +32,7 @@ GLSA <%= h id %> <%= h GLSARepository.instance[id].title %> - <%= h GLSARepository.instance[id].date %> + <%= date_format GLSARepository.instance[id].date %> <% end %> diff --git a/views/layout.erb b/views/layout.erb index c55548e..443313b 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -5,7 +5,7 @@ - + -- cgit v1.2.3-65-gdbad