КОНТРОЛЫ/time.md


Исходный код

Twig код

{% set times_items = [
  {value:'00:00', time:0000}, {value:'00:30', time:0030}, {value:'01:00', time:0100}, {value:'01:30', time:0130},
  {value:'02:00', time:0200}, {value:'02:30', time:0230}, {value:'03:00', time:0300}, {value:'03:30', time:0330},
  {value:'04:00', time:0400}, {value:'04:30', time:0430}, {value:'05:00', time:0500}, {value:'05:30', time:0530},
  {value:'06:00', time:0600}, {value:'06:30', time:0630}, {value:'07:00', time:0700}, {value:'07:30', time:0730},
  {value:'08:00', time:0800}, {value:'08:30', time:0830}, {value:'09:00', time:0900}, {value:'09:30', time:0930},
  {value:'10:00', time:1000}, {value:'10:30', time:1030}, {value:'11:00', time:1100}, {value:'11:30', time:1130},
  {value:'12:00', time:1200}, {value:'12:30', time:1230}, {value:'13:00', time:1300}, {value:'13:30', time:1330},
  {value:'14:00', time:1400}, {value:'14:30', time:1430}, {value:'15:00', time:1500}, {value:'15:30', time:1530},
  {value:'16:00', time:1600}, {value:'16:30', time:1630}, {value:'17:00', time:1700}, {value:'17:30', time:1730},
  {value:'18:00', time:1800}, {value:'18:30', time:1830}, {value:'19:00', time:1900}, {value:'19:30', time:1930},
  {value:'20:00', time:2000}, {value:'20:30', time:2030}, {value:'21:00', time:2100}, {value:'21:30', time:2130},
  {value:'22:00', time:2200}, {value:'22:30', time:2230}, {value:'23:00', time:2300}, {value:'23:30', time:2330}
] %}


{% if _time_format == 12 %}
  {% set times_items = [
    {value:'12:00AM', time:0000}, {value:'12:30AM', time:0030}, {value: '1:00AM', time:0100}, {value: '1:30AM', time:0130},
    {value: '2:00AM', time:0200}, {value: '2:30AM', time:0230}, {value: '3:00AM', time:0300}, {value: '3:30AM', time:0330},
    {value: '4:00AM', time:0400}, {value: '4:30AM', time:0430}, {value: '5:00AM', time:0500}, {value: '5:30AM', time:0530},
    {value: '6:00AM', time:0600}, {value: '6:30AM', time:0630}, {value: '7:00AM', time:0700}, {value: '7:30AM', time:0730},
    {value: '8:00AM', time:0800}, {value: '8:30AM', time:0830}, {value: '9:00AM', time:0900}, {value: '9:30AM', time:0930},
    {value:'10:00AM', time:1000}, {value:'10:30AM', time:1030}, {value:'11:00AM', time:1100}, {value:'11:30AM', time:1130},
    {value:'12:00PM', time:1200}, {value:'12:30PM', time:1230}, {value: '1:00PM', time:1300}, {value: '1:30PM', time:1330},
    {value: '2:00PM', time:1400}, {value: '2:30PM', time:1430}, {value: '3:00PM', time:1500}, {value: '3:30PM', time:1530},
    {value: '4:00PM', time:1600}, {value: '4:30PM', time:1630}, {value: '5:00PM', time:1700}, {value: '5:30PM', time:1730},
    {value: '6:00PM', time:1800}, {value: '6:30PM', time:1830}, {value: '7:00PM', time:1900}, {value: '7:30PM', time:1930},
    {value: '8:00PM', time:2000}, {value: '8:30PM', time:2030}, {value: '9:00PM', time:2100}, {value: '9:30PM', time:2130},
    {value:'10:00PM', time:2200}, {value:'10:30PM', time:2230}, {value:'11:00PM', time:2300}, {value:'11:30PM', time:2330}
  ] %}
{% endif %}

{% if time_intervals is defined %}
  {% set times_items = [
    {value:'00:00', time:0000}, {value:'00:15', time:0015}, {value:'00:30', time:0030}, {value:'00:45', time:0045},
    {value:'01:00', time:0100}, {value:'01:15', time:0115}, {value:'01:30', time:0130}, {value:'01:45', time:0145},
    {value:'02:00', time:0200}, {value:'02:15', time:0215}, {value:'02:30', time:0230}, {value:'02:45', time:0245},
    {value:'03:00', time:0300}, {value:'03:15', time:0315}, {value:'03:30', time:0330}, {value:'03:45', time:0345},
    {value:'04:00', time:0400}, {value:'04:15', time:0415}, {value:'04:30', time:0430}, {value:'04:45', time:0445},
    {value:'05:00', time:0500},
  ] %}
{% endif %}

{% set items = [] %}

{% for times_item in times_items %}
  {% set keep_item = true %}
  {% if skip_before_time is defined and times_item.time < skip_before_time %}
    {% set keep_item = false %}
  {% endif %}
  {% if keep_item %}
    {% set items = items|merge([
      {
        value: times_item.value,
        option: times_item.value,
      }
    ]) %}
  {% endif %}
{% endfor %}

{% if not selected and not selected_should_be_empty %}
  {% if not date %}
    {% set date = "today"|task_date('timestamp', true, true) %}
    {% set selected = date|task_date('time', true) %}
  {% else %}
    {% set selected = date|task_date('time', true) %}
  {% endif %}
{% endif %}

{% if time %}
  {% set selected = items[time].value %}
{% endif %}

{% if not name %}
  {% set name = 'time' %}
{% endif %}

{% if not id %}
  {% set id = 'task_edit_time' %}
{% endif %}

{% include "interface/controls/" ~ input_tmpl ~ ".twig" with {
  items: items,
  id: id,
  selected: selected,
  name: name,
  class_name: class_name,
  input_class_name: 'js-control-time-formatter ' ~ input_class_name,
  additional_data: additional_data or '',
  selected_should_be_empty: selected_should_be_empty
} %}
Ссылка на вики репозиторий