Commit dc6c5813 authored by Leandro Nunes's avatar Leandro Nunes
Browse files

Adapting views and helpers to datime format

parent e021f701
......@@ -51,7 +51,7 @@ module ContentViewerHelper
elsif date_format == 'past_time'
left_time = true
end
content_tag('span', show_date(article.published_at, use_numbers , year, left_time), :class => 'date')
content_tag('span', show_time(article.published_at, use_numbers , year, left_time), :class => 'date')
end
def link_to_comments(article, args = {})
......
......@@ -43,9 +43,9 @@ module DatesHelper
end
# formats a datetime for displaying.
def show_time(time, use_numbers = true, year = true, left_time = false)
def show_time(time, use_numbers = false, year = true, left_time = false)
if time && use_numbers
_('%{day} %{month} %{year}, %{hour}:%{minutes}') % { :year => time.year, :month => month_name(time.month), :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") }
_('%{month}/%{day}/%{year}, %{hour}:%{minutes}') % { :year => (year ? time.year : ''), :month => time.month, :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") }
elsif time && left_time
date_format = time_ago_in_words(time)
elsif time
......@@ -77,8 +77,8 @@ module DatesHelper
end
else
_('from %{date1} to %{date2}') % {
:date1 => show_date(date1, use_numbers),
:date2 => show_date(date2, use_numbers)
:date1 => show_time(date1, use_numbers),
:date2 => show_time(date2, use_numbers)
}
end
end
......
......@@ -151,7 +151,7 @@ module FormsHelper
datepicker_options[:close_text] ||= _('Done')
datepicker_options[:constrain_input] ||= true
datepicker_options[:current_text] ||= _('Today')
datepicker_options[:date_format] ||= 'mm/dd/yy'
datepicker_options[:date_format] ||= 'yy/mm/dd'
datepicker_options[:day_names] ||= [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')]
datepicker_options[:day_names_min] ||= [_('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr'), _('Sa')]
datepicker_options[:day_names_short] ||= [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat')]
......@@ -236,7 +236,7 @@ module FormsHelper
weekHeader: #{datepicker_options[:week_header].to_json},
yearRange: #{datepicker_options[:year_range].to_json},
yearSuffix: #{datepicker_options[:year_suffix].to_json}
})
}).datepicker('setDate', new Date('#{value}'))
</script>
".html_safe
result
......
......@@ -8,9 +8,8 @@
<%= render :partial => 'general_fields' %>
<%= render :partial => 'translatable' %>
<%= labelled_form_field(_('Start date'), date_field('article[start_date]', @article.start_date,_('%Y-%m-%d'), {:time => true}, {:id => 'article_start_date'} )) %>
<%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, _('%Y-%m-%d %H:%M'), {:time => true}, {:id => 'article_start_date'} ) %>
<%= labelled_form_field(_('End date'), date_field('article[end_date]', @article.end_date, _('%Y-%m-%d'), {:time => true}, {:id => 'article_end_date'})) %>
<%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %>
......
<span class="publishing-info">
<span class="date">
<%= show_date(@page.published_at) %>
<%= show_time(@page.published_at) %>
</span>
<span class="author">
<%= _(", by %s") % (@page.author ? link_to(@page.author_name, @page.author_url) : @page.author_name) %>
......
......@@ -16,14 +16,14 @@ class ContentViewerHelperTest < ActionView::TestCase
blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id)
post = create(TextileArticle, :name => 'post test', :profile => profile, :parent => blog)
result = article_title(post)
assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at)
assert_tag_in_string result, :tag => 'span', :content => show_time(post.published_at)
end
should 'display published-at for forum posts' do
forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id)
post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => forum)
result = article_title(post)
assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at)
assert_tag_in_string result, :tag => 'span', :content => show_time(post.published_at)
end
should 'not display published-at for non-blog and non-forum posts' do
......
......@@ -21,23 +21,23 @@ class DatesHelperTest < ActiveSupport::TestCase
should 'generate period with two dates' do
date1 = mock
date1.stubs(:year).returns('A')
expects(:show_date).with(date1, anything).returns('XXX')
expects(:show_time).with(date1, anything).returns('XXX')
date2 = mock
date2.stubs(:year).returns('B')
expects(:show_date).with(date2, anything).returns('YYY')
expects(:show_time).with(date2, anything).returns('YYY')
expects(:_).with('from %{date1} to %{date2}').returns('from %{date1} to %{date2}')
assert_equal 'from XXX to YYY', show_period(date1, date2)
end
should 'generate period with in two diferent years' do
date1 = Date.new(1920, 1, 2)
date2 = Date.new(1992, 4, 6)
assert_equal 'from January 2, 1920 to April 6, 1992', show_period(date1, date2)
date1 = DateTime.new(1920, 1, 2)
date2 = DateTime.new(1992, 4, 6)
assert_equal 'from January 2, 1920 0:00 to April 6, 1992 0:00', show_period(date1, date2)
end
should 'generate period with in two diferent months of the same year' do
date1 = Date.new(2013, 2, 1)
date2 = Date.new(2013, 3, 1)
date1 = DateTime.new(2013, 2, 1)
date2 = DateTime.new(2013, 3, 1)
assert_equal 'from February 1 to March 1, 2013', show_period(date1, date2)
end
......@@ -49,13 +49,13 @@ class DatesHelperTest < ActiveSupport::TestCase
should 'generate period with two equal dates' do
date1 = mock
expects(:show_date).with(date1, anything).returns('XXX')
expects(:show_time).with(date1, anything).returns('XXX')
assert_equal 'XXX', show_period(date1, date1)
end
should 'generate period with one date only' do
date1 = mock
expects(:show_date).with(date1, anything).returns('XXX')
expects(:show_time).with(date1, anything).returns('XXX')
assert_equal 'XXX', show_period(date1)
end
......@@ -118,16 +118,16 @@ class DatesHelperTest < ActiveSupport::TestCase
end
should 'format time' do
assert_equal '22 November 2008, 15:34', show_time(Time.mktime(2008, 11, 22, 15, 34, 0, 0))
assert_equal 'November 22, 2008 15:34', show_time(Time.mktime(2008, 11, 22, 15, 34, 0, 0))
end
should 'format time with 2 digits minutes' do
assert_equal '22 November 2008, 15:04', show_time(Time.mktime(2008, 11, 22, 15, 04, 0, 0))
assert_equal 'November 22, 2008 15:04', show_time(Time.mktime(2008, 11, 22, 15, 04, 0, 0))
end
should 'translate time' do
time = Time.parse('25 May 2009, 12:47')
assert_equal '25 May 2009, 12:47', show_time(time)
assert_equal 'May 25, 2009 12:47', show_time(time)
end
should 'handle nil time' do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment