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