Commit e7aea8e41bd996438d92e3188c1ce70acde2a478
Exists in
master
and in
11 other branches
Merge pull request #102 from codesnik/symbol_formats
Allow symbols for format: option
Showing
3 changed files
with
10 additions
and
2 deletions
Show diff stats
README.md
... | ... | @@ -158,7 +158,7 @@ User.group_by_hour_of_day(:created_at, format: "%-l %P").count |
158 | 158 | # } |
159 | 159 | ``` |
160 | 160 | |
161 | -Takes a `String`, which is passed to [strftime](http://strfti.me/), or a `Proc`. You can pass a locale with the `locale` option. | |
161 | +Takes a `String`, which is passed to [strftime](http://strfti.me/), or a `Symbol`, which is looked up by `I18n.localize` in `i18n` scope 'time.formats', or a `Proc`. You can pass a locale with the `locale` option. | |
162 | 162 | |
163 | 163 | ### Dynamic Grouping |
164 | 164 | ... | ... |
lib/groupdate/magic.rb
... | ... | @@ -245,7 +245,7 @@ module Groupdate |
245 | 245 | when :month_of_year |
246 | 246 | key = Date.new(2014, key, 1).to_time |
247 | 247 | end |
248 | - I18n.localize(key, format: options[:format].to_s, locale: locale) | |
248 | + I18n.localize(key, format: options[:format], locale: locale) | |
249 | 249 | end |
250 | 250 | end |
251 | 251 | else | ... | ... |
test/test_helper.rb
... | ... | @@ -26,6 +26,9 @@ end |
26 | 26 | I18n.enforce_available_locales = true |
27 | 27 | I18n.backend.store_translations :de, date: { |
28 | 28 | abbr_month_names: %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil) |
29 | +}, | |
30 | +time: { | |
31 | + formats: {special: '%b %e, %Y'} | |
29 | 32 | } |
30 | 33 | |
31 | 34 | # migrations |
... | ... | @@ -758,6 +761,11 @@ module TestGroupdate |
758 | 761 | assert_equal ({"Okt" => 1}), User.group_by_day(:created_at, format: "%b", locale: :de).count |
759 | 762 | end |
760 | 763 | |
764 | + def test_format_locale_by_symbol | |
765 | + create_user "2014-10-01 00:00:00 UTC" | |
766 | + assert_equal ({"Okt 1, 2014" => 1}), User.group_by_day(:created_at, format: :special, locale: :de).count | |
767 | + end | |
768 | + | |
761 | 769 | def test_format_locale_global |
762 | 770 | create_user "2014-10-01 00:00:00 UTC" |
763 | 771 | I18n.locale = :de | ... | ... |