Time API
Per-option reference for the :time field. For tasks and examples, see the Time guide.
Options are passed to a field declaration in an Avo resource, such as app/avo/resources/event.rb:
field :starting_at, as: :timeShared options, including link_to_record, are covered in common field options.
Display formatting
-> format
The format used on Index and Show pages. Locale-sensitive tokens use the page's locale.
field :starting_at, as: :time, format: "HH:mm"- Type:
String - Default:
"TT" - Values: Luxon formatting tokens.
-> picker_format
The visible input format on New and Edit pages. It does not change the submitted time format.
field :starting_at, as: :time, picker_format: "H:i"- Type:
String - Default:
"H:i:S" - Values: flatpickr formatting tokens.
Different token systems
format uses Luxon tokens; picker_format uses flatpickr tokens. They are not interchangeable.
Timezone conversion
-> relative
Controls whether the time is converted from UTC to the display timezone. This is timezone conversion, not relative wording such as "two hours ago".
field :starting_at, as: :time, relative: false| Value | Behavior |
|---|---|
true | Displays and edits in the configured timezone, or the browser's timezone when none is configured; picker changes are converted back to UTC. |
false | Displays the UTC clock time on Index and Show; the picker retains that clock time and submits it without applying a timezone offset. |
- Type:
Boolean - Default:
true
Date used for conversion
For time-only values, Avo reparses the UTC clock time using today's date before converting it for display or editing. Offsets therefore follow today's daylight saving rules, not the date attached to the stored value.
-> timezone
The display timezone when relative is true. A block can return a different timezone for each record.
field :starting_at, as: :time, timezone: -> { record.timezone }- Type:
StringorProc/Lambdareturning a timezone identifier ornil - Default:
nil(uses the browser's timezone) - Values: Timezone identifiers understood by Luxon, such as
"America/Los_Angeles"or"UTC". See also Rails' timezone documentation. - Context: Blocks run in
Avo::ExecutionContextwithrecord,resource, andviewavailable.
INFO
With relative: false, the configured timezone does not shift the displayed clock time. Avo normalizes "UTC" to "Etc/UTC" on form views for compatibility with Luxon.
Picker controls
-> time_24hr
Controls the picker's hour selection. Index and Show formatting is controlled separately by format.
field :starting_at, as: :time, time_24hr: true| Value | Behavior |
|---|---|
false | Uses AM/PM selection. |
true | Uses 24-hour selection. |
- Type:
Boolean - Default:
false
-> disable_mobile
Disables flatpickr's native mobile picker fallback. See flatpickr mobile support.
field :starting_at, as: :time, disable_mobile: true| Value | Behavior |
|---|---|
false | Allows a native mobile picker where flatpickr supports it. |
true | Uses flatpickr on mobile too. |
- Type:
Boolean - Default:
false
-> picker_options
Additional flatpickr options, applied on New and Edit pages. Avo fills locale.weekdays and locale.months from the app locale and merges a supplied locale over them. The Time field has no calendar.
field :starting_at, as: :time, picker_options: { minTime: "09:00" }- Type:
Hash - Default:
{} - Values: flatpickr options.
- Validation: These settings constrain the picker, not server-side model validation.
Avo-controlled settings
Avo sets altFormat, disableMobile, locale.firstDayOfWeek, enableTime, enableSeconds, noCalendar, and dateFormat after merging picker_options. Avo also supplies defaultDate when the field has a value. Those settings cannot be overridden through this Hash. Other options, including time_24hr and callbacks, are forwarded to flatpickr and can replace Avo's defaults.