Class: RailsAdmin::Config::Fields::Types::Datetime

Inherits:
Base
  • Object
show all
Defined in:
lib/russian/rails_admin_datetime.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.normalize(date_string, format) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/russian/rails_admin_datetime.rb', line 11

def normalize(date_string, format)
  unless I18n.locale == "en"
    format.to_s.scan(/%[AaBbp]/) do |match|
      case match
      when '%B'
        english = I18n.t('date.month_names', :locale => :en)[1..-1]
        common_month_names = I18n.t('date.common_month_names')[1..-1]
        common_month_names.each_with_index {|m, i| date_string = date_string.gsub(/#{m}/i, english[i]) }
      when '%b'
        english = I18n.t('date.abbr_month_names', :locale => :en)[1..-1]
        common_abbr_month_names = I18n.t('date.common_abbr_month_names')[1..-1]
        common_abbr_month_names.each_with_index {|m, i| date_string = date_string.gsub(/#{m}/i, english[i]) }
      end
    end
  end
  normalize_without_russian(date_string, format)
end

.normalize_without_russianObject



10
# File 'lib/russian/rails_admin_datetime.rb', line 10

alias_method :normalize_without_russian, :normalize

Instance Method Details

#formatted_date_valueObject



30
31
32
33
# File 'lib/russian/rails_admin_datetime.rb', line 30

def formatted_date_value
  value = bindings[:object].new_record? && self.value.nil? && !self.default_value.nil? ? self.default_value : self.value
  value.nil? ? "" : (I18n.l(value, format: '%2d').strip + ' ' + I18n.l(value, format: '%B %Y').strip)
end

#valueObject



35
36
37
# File 'lib/russian/rails_admin_datetime.rb', line 35

def value
  bindings[:object].send(name)
end