Class: Avo::Fields::DateTimeField
- Defined in:
- lib/avo/fields/date_time_field.rb
Defined Under Namespace
Classes: EditComponent, IndexComponent, ShowComponent
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#time_24hr ⇒ Object
readonly
Returns the value of attribute time_24hr.
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
Attributes inherited from DateField
#first_day_of_week, #picker_format, #relative
Attributes inherited from TextField
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #model, #null_values, #nullable, #panel_name, #readonly, #required, #resource, #sortable, #updatable, #user, #view, #visible
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #fill_field(model, key, value, params) ⇒ Object
- #formatted_value ⇒ Object
-
#initialize(id, **args, &block) ⇒ DateTimeField
constructor
A new instance of DateTimeField.
Methods inherited from BaseField
#component_for_view, #custom?, #database_id, #has_own_panel?, #hydrate, #model_errors, #name, #placeholder, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?
Methods included from FieldExtensions::HasFieldName
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(id, **args, &block) ⇒ DateTimeField
Returns a new instance of DateTimeField.
8 9 10 11 12 13 14 |
# File 'lib/avo/fields/date_time_field.rb', line 8 def initialize(id, **args, &block) super(id, **args, &block) @picker_format = args[:picker_format].present? ? args[:picker_format] : "Y-m-d H:i:S" @time_24hr = args[:time_24hr].present? ? args[:time_24hr] : false @timezone = args[:timezone].present? ? args[:timezone] : Rails.application.config.time_zone end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
4 5 6 |
# File 'lib/avo/fields/date_time_field.rb', line 4 def format @format end |
#time_24hr ⇒ Object (readonly)
Returns the value of attribute time_24hr.
5 6 7 |
# File 'lib/avo/fields/date_time_field.rb', line 5 def time_24hr @time_24hr end |
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
6 7 8 |
# File 'lib/avo/fields/date_time_field.rb', line 6 def timezone @timezone end |
Instance Method Details
#fill_field(model, key, value, params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/avo/fields/date_time_field.rb', line 26 def fill_field(model, key, value, params) if value.nil? model[id] = nil return model end return model if value.blank? model[id] = value.to_time.in_time_zone(Rails.application.config.time_zone) model end |
#formatted_value ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/avo/fields/date_time_field.rb', line 16 def formatted_value return nil if value.nil? if @format.is_a?(Symbol) value.to_time.in_time_zone(timezone).to_formatted_s(@format) else value.to_time.in_time_zone(timezone).strftime(@format) end end |