Commit dc6c581308f8dfecd4d3ddb62890643d237d6669

Authored by Leandro Santos
1 parent e021f701

Adapting views and helpers to datime format

app/helpers/content_viewer_helper.rb
... ... @@ -51,7 +51,7 @@ module ContentViewerHelper
51 51 elsif date_format == 'past_time'
52 52 left_time = true
53 53 end
54   - content_tag('span', show_date(article.published_at, use_numbers , year, left_time), :class => 'date')
  54 + content_tag('span', show_time(article.published_at, use_numbers , year, left_time), :class => 'date')
55 55 end
56 56  
57 57 def link_to_comments(article, args = {})
... ...
app/helpers/dates_helper.rb
... ... @@ -43,9 +43,9 @@ module DatesHelper
43 43 end
44 44  
45 45 # formats a datetime for displaying.
46   - def show_time(time, use_numbers = true, year = true, left_time = false)
  46 + def show_time(time, use_numbers = false, year = true, left_time = false)
47 47 if time && use_numbers
48   - _('%{day} %{month} %{year}, %{hour}:%{minutes}') % { :year => time.year, :month => month_name(time.month), :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") }
  48 + _('%{month}/%{day}/%{year}, %{hour}:%{minutes}') % { :year => (year ? time.year : ''), :month => time.month, :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") }
49 49 elsif time && left_time
50 50 date_format = time_ago_in_words(time)
51 51 elsif time
... ... @@ -77,8 +77,8 @@ module DatesHelper
77 77 end
78 78 else
79 79 _('from %{date1} to %{date2}') % {
80   - :date1 => show_date(date1, use_numbers),
81   - :date2 => show_date(date2, use_numbers)
  80 + :date1 => show_time(date1, use_numbers),
  81 + :date2 => show_time(date2, use_numbers)
82 82 }
83 83 end
84 84 end
... ...
app/helpers/forms_helper.rb
... ... @@ -151,7 +151,7 @@ module FormsHelper
151 151 datepicker_options[:close_text] ||= _('Done')
152 152 datepicker_options[:constrain_input] ||= true
153 153 datepicker_options[:current_text] ||= _('Today')
154   - datepicker_options[:date_format] ||= 'mm/dd/yy'
  154 + datepicker_options[:date_format] ||= 'yy/mm/dd'
155 155 datepicker_options[:day_names] ||= [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')]
156 156 datepicker_options[:day_names_min] ||= [_('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr'), _('Sa')]
157 157 datepicker_options[:day_names_short] ||= [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat')]
... ... @@ -236,7 +236,7 @@ module FormsHelper
236 236 weekHeader: #{datepicker_options[:week_header].to_json},
237 237 yearRange: #{datepicker_options[:year_range].to_json},
238 238 yearSuffix: #{datepicker_options[:year_suffix].to_json}
239   - })
  239 + }).datepicker('setDate', new Date('#{value}'))
240 240 </script>
241 241 ".html_safe
242 242 result
... ...
app/views/cms/_event.html.erb
... ... @@ -8,9 +8,8 @@
8 8 <%= render :partial => 'general_fields' %>
9 9 <%= render :partial => 'translatable' %>
10 10  
11   -<%= labelled_form_field(_('Start date'), date_field('article[start_date]', @article.start_date,_('%Y-%m-%d'), {:time => true}, {:id => 'article_start_date'} )) %>
  11 +<%= 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'} ) %>
12 12  
13   -<%= labelled_form_field(_('End date'), date_field('article[end_date]', @article.end_date, _('%Y-%m-%d'), {:time => true}, {:id => 'article_end_date'})) %>
14 13  
15 14 <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %>
16 15  
... ...
app/views/content_viewer/_publishing_info.html.erb
1 1 <span class="publishing-info">
2 2 <span class="date">
3   - <%= show_date(@page.published_at) %>
  3 + <%= show_time(@page.published_at) %>
4 4 </span>
5 5 <span class="author">
6 6 <%= _(", by %s") % (@page.author ? link_to(@page.author_name, @page.author_url) : @page.author_name) %>
... ...
test/unit/content_viewer_helper_test.rb
... ... @@ -16,14 +16,14 @@ class ContentViewerHelperTest &lt; ActionView::TestCase
16 16 blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id)
17 17 post = create(TextileArticle, :name => 'post test', :profile => profile, :parent => blog)
18 18 result = article_title(post)
19   - assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at)
  19 + assert_tag_in_string result, :tag => 'span', :content => show_time(post.published_at)
20 20 end
21 21  
22 22 should 'display published-at for forum posts' do
23 23 forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id)
24 24 post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => forum)
25 25 result = article_title(post)
26   - assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at)
  26 + assert_tag_in_string result, :tag => 'span', :content => show_time(post.published_at)
27 27 end
28 28  
29 29 should 'not display published-at for non-blog and non-forum posts' do
... ...
test/unit/dates_helper_test.rb
... ... @@ -21,23 +21,23 @@ class DatesHelperTest &lt; ActiveSupport::TestCase
21 21 should 'generate period with two dates' do
22 22 date1 = mock
23 23 date1.stubs(:year).returns('A')
24   - expects(:show_date).with(date1, anything).returns('XXX')
  24 + expects(:show_time).with(date1, anything).returns('XXX')
25 25 date2 = mock
26 26 date2.stubs(:year).returns('B')
27   - expects(:show_date).with(date2, anything).returns('YYY')
  27 + expects(:show_time).with(date2, anything).returns('YYY')
28 28 expects(:_).with('from %{date1} to %{date2}').returns('from %{date1} to %{date2}')
29 29 assert_equal 'from XXX to YYY', show_period(date1, date2)
30 30 end
31 31  
32 32 should 'generate period with in two diferent years' do
33   - date1 = Date.new(1920, 1, 2)
34   - date2 = Date.new(1992, 4, 6)
35   - assert_equal 'from January 2, 1920 to April 6, 1992', show_period(date1, date2)
  33 + date1 = DateTime.new(1920, 1, 2)
  34 + date2 = DateTime.new(1992, 4, 6)
  35 + assert_equal 'from January 2, 1920 0:00 to April 6, 1992 0:00', show_period(date1, date2)
36 36 end
37 37  
38 38 should 'generate period with in two diferent months of the same year' do
39   - date1 = Date.new(2013, 2, 1)
40   - date2 = Date.new(2013, 3, 1)
  39 + date1 = DateTime.new(2013, 2, 1)
  40 + date2 = DateTime.new(2013, 3, 1)
41 41 assert_equal 'from February 1 to March 1, 2013', show_period(date1, date2)
42 42 end
43 43  
... ... @@ -49,13 +49,13 @@ class DatesHelperTest &lt; ActiveSupport::TestCase
49 49  
50 50 should 'generate period with two equal dates' do
51 51 date1 = mock
52   - expects(:show_date).with(date1, anything).returns('XXX')
  52 + expects(:show_time).with(date1, anything).returns('XXX')
53 53 assert_equal 'XXX', show_period(date1, date1)
54 54 end
55 55  
56 56 should 'generate period with one date only' do
57 57 date1 = mock
58   - expects(:show_date).with(date1, anything).returns('XXX')
  58 + expects(:show_time).with(date1, anything).returns('XXX')
59 59 assert_equal 'XXX', show_period(date1)
60 60 end
61 61  
... ... @@ -118,16 +118,16 @@ class DatesHelperTest &lt; ActiveSupport::TestCase
118 118 end
119 119  
120 120 should 'format time' do
121   - assert_equal '22 November 2008, 15:34', show_time(Time.mktime(2008, 11, 22, 15, 34, 0, 0))
  121 + assert_equal 'November 22, 2008 15:34', show_time(Time.mktime(2008, 11, 22, 15, 34, 0, 0))
122 122 end
123 123  
124 124 should 'format time with 2 digits minutes' do
125   - assert_equal '22 November 2008, 15:04', show_time(Time.mktime(2008, 11, 22, 15, 04, 0, 0))
  125 + assert_equal 'November 22, 2008 15:04', show_time(Time.mktime(2008, 11, 22, 15, 04, 0, 0))
126 126 end
127 127  
128 128 should 'translate time' do
129 129 time = Time.parse('25 May 2009, 12:47')
130   - assert_equal '25 May 2009, 12:47', show_time(time)
  130 + assert_equal 'May 25, 2009 12:47', show_time(time)
131 131 end
132 132  
133 133 should 'handle nil time' do
... ...