Class: Jav::Fields::DateTimeField
- Defined in:
- lib/jav/fields/date_time_field.rb
Direct Known Subclasses
Defined Under Namespace
Classes: EditComponent, IndexComponent, ShowComponent
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#picker_format ⇒ Object
readonly
Returns the value of attribute picker_format.
-
#relative ⇒ Object
readonly
Returns the value of attribute relative.
-
#time_24hr ⇒ Object
readonly
Returns the value of attribute time_24hr.
Attributes inherited from DateField
#disable_mobile, #first_day_of_week, #picker_options
Attributes inherited from TextField
#as_html, #link_to_resource, #protocol
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #autocomplete, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #in_sidebar, #index_text_align, #model, #null_values, #nullable, #panel_name, #readonly, #required, #resource, #sortable, #stacked, #user, #view, #visible
Attributes included from Concerns::IsDisabled
Attributes included from Concerns::HasHTMLAttributes
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #edit_formatted_value ⇒ Object
- #fill_field(model, key, value, params) ⇒ Object
- #formatted_value ⇒ Object
-
#initialize(id, **args, &block) ⇒ DateTimeField
constructor
A new instance of DateTimeField.
- #timezone ⇒ Object
- #utc_time(value) ⇒ Object
Methods inherited from BaseField
#assign_value, #component_for_view, #custom?, #custom_name?, #database_id, #default_name, #has_own_panel?, #hidden_in_reflection?, #hydrate, #model_errors, #name, #placeholder, #plural_name, #resolve_attribute, #to_permitted_param, #translation_key, #type, #updatable, #update_using, #value, #view_component_name, #visible?, #visible_in_reflection?
Methods included from FieldExtensions::HasFieldName
Methods included from Concerns::HasDefault
Methods included from Concerns::IsDisabled
Methods included from Concerns::IsReadonly
Methods included from Concerns::IsRequired
Methods included from Concerns::HasHTMLAttributes
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on, #show_on_create, #show_on_update, #visible_on?
Methods included from Concerns::IsResourceItem
#is_field?, #is_main_panel?, #is_panel?, #is_row?, #is_sidebar?, #is_tab?, #is_tab_group?, #is_tool?
Constructor Details
#initialize(id, **args, &block) ⇒ DateTimeField
Returns a new instance of DateTimeField.
6 7 8 9 10 11 12 13 14 |
# File 'lib/jav/fields/date_time_field.rb', line 6 def initialize(id, **args, &block) super add_boolean_prop args, :time_24hr add_string_prop args, :picker_format, "Y-m-d H:i:S" add_string_prop args, :format, "yyyy-LL-dd TT" add_string_prop args, :timezone add_boolean_prop args, :relative, true end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
4 5 6 |
# File 'lib/jav/fields/date_time_field.rb', line 4 def format @format end |
#picker_format ⇒ Object (readonly)
Returns the value of attribute picker_format.
4 5 6 |
# File 'lib/jav/fields/date_time_field.rb', line 4 def picker_format @picker_format end |
#relative ⇒ Object (readonly)
Returns the value of attribute relative.
4 5 6 |
# File 'lib/jav/fields/date_time_field.rb', line 4 def relative @relative end |
#time_24hr ⇒ Object (readonly)
Returns the value of attribute time_24hr.
4 5 6 |
# File 'lib/jav/fields/date_time_field.rb', line 4 def time_24hr @time_24hr end |
Instance Method Details
#edit_formatted_value ⇒ Object
22 23 24 25 26 |
# File 'lib/jav/fields/date_time_field.rb', line 22 def edit_formatted_value return nil if value.nil? value.utc.iso8601 end |
#fill_field(model, key, value, params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jav/fields/date_time_field.rb', line 28 def fill_field(model, key, value, params) if value.in?(["", nil]) model[id] = value return model end return model if value.blank? model[id] = utc_time(value) model end |
#formatted_value ⇒ Object
16 17 18 19 20 |
# File 'lib/jav/fields/date_time_field.rb', line 16 def formatted_value return nil if value.nil? value.utc.to_time.iso8601 end |
#timezone ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jav/fields/date_time_field.rb', line 52 def timezone timezone = if @timezone.respond_to?(:call) return Jav::Hosts::ResourceViewRecordHost.new(block: @timezone, record: resource.model, resource: resource, view: view).handle else @timezone end # Fix for https://github.com/moment/luxon/issues/1358#issuecomment-2017477897 return "Etc/UTC" if timezone&.downcase == "utc" && view.in?(i[new create edit update]) timezone end |
#utc_time(value) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/jav/fields/date_time_field.rb', line 42 def utc_time(value) time = Time.zone.parse(value) if timezone.present? && !time.utc? ActiveSupport::TimeZone.new(timezone).local_to_utc(time) else value end end |