class RailsAdmin::Support::Datetime
Constants
- FLATPICKR_TRANSLATIONS
Ruby format options as a key and flatpickr format options as a value
Public Class Methods
to_flatpickr_format(strftime_format)
click to toggle source
# File lib/rails_admin/support/datetime.rb, line 47 def to_flatpickr_format(strftime_format) strftime_format.gsub(/(?<!%)(?<![-0-9:])\w/, '\\\\\0').gsub(/%([-0-9:]?\w)/) do |match| # Timezone can't be handled by frontend, the server's one is always used case match when '%Z', '%:z' # Time zone as hour and minute offset from UTC with a colon (e.g. +09:00) Time.zone.formatted_offset when '%z' # Time zone as hour and minute offset from UTC (e.g. +0900) Time.zone.formatted_offset(false) else FLATPICKR_TRANSLATIONS[match] or raise <<~MSG Unsupported strftime directive '#{match}' was found. Please consider explicitly setting flatpickr_format instance option for the field. field(:name_of_field) { flatpickr_format '...' } MSG end end end