Class: CckForms::ParameterTypeClass::DateTime
- Inherits:
-
Object
- Object
- CckForms::ParameterTypeClass::DateTime
- Includes:
- DateTime, Base
- Defined in:
- lib/cck_forms/parameter_type_class/date_time.rb
Overview
Represents a single date & time.
Instance Method Summary collapse
-
#build_form(form_builder, options) ⇒ Object
Date and time SELECTs.
-
#to_s(options = nil) ⇒ Object
Options is a :symbol -> options = true:.
Methods included from DateTime
Methods included from DateTime::DateTimeParser
#date_object_from_what_stored_in_database
Instance Method Details
#build_form(form_builder, options) ⇒ Object
Date and time SELECTs
8 9 10 11 12 13 14 15 |
# File 'lib/cck_forms/parameter_type_class/date_time.rb', line 8 def build_form(form_builder, ) set_value_in_hash value = CckForms::ParameterTypeClass::Time::date_object_from_what_stored_in_database([:value]) , form_element_html = CckForms::ParameterTypeClass::Time.(value, ) .merge!({minute_step: 5}) form_element_html.merge!({required: [:required]}) ('<div class="form-inline">%s</div>' % form_builder.fields_for(:value) { |datetime_builder| datetime_builder.datetime_select '', , form_element_html}) end |
#to_s(options = nil) ⇒ Object
Options is a :symbol -> options = true:
date_attr.to_s :only_date
date_attr.to_s :only_date => true # equivalent
options:
year_obligatory - force year in output (by default current year is skipped)
only_date - hide time
rus_date - Russian date, like "2 июля"
By default: “01.02.2012, 12:49”.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cck_forms/parameter_type_class/date_time.rb', line 29 def to_s(=nil) value = if self.value.is_a? Time { '(1i)' => self.value.year, '(2i)' => self.value.month, '(3i)' => self.value.day, '(4i)' => self.value.hour, '(5i)' => self.value.min, } else self.value end return '' unless value and value.is_a?(Hash) and value.try(:[], '(1i)').to_i > 0 and value.try(:[], '(2i)').to_i > 0 and value.try(:[], '(3i)').to_i > 0 = { => true} if .is_a? Symbol = {} unless .is_a? Hash now = Date::today date = DateTime.new value.try(:[], '(1i)').to_i, value.try(:[], '(2i)').to_i, value.try(:[], '(3i)').to_i, value.try(:[], '(4i)').to_i, value.try(:[], '(5i)').to_i date = date.in_time_zone(Rails.application.config.time_zone) need_year = [:year_obligatory] || now.strftime('%Y') != date.strftime('%Y') if [:rus_date] date_string = Russian::strftime(date, '%e %B' + (need_year ? ' %Y' : '')) # 2 июля else date_string = date.strftime('%d.%m' + (need_year ? '.%Y' : '')) end time_string = date.strftime '%H:%M' if [:only_date] return date_string else return "#{date_string}, #{time_string}" end rescue '' end |