How do I create a time range form field? Is there any way to add time range input fields in a form, for example using code similar to the following one?

$form['notification_hours'] = array(
  '#type' =&gt; 'time_range', // type time_range doesn't work
  '#title' =&gt; $this-&gt;t('Notification hours:'),
  '#default_value' =&gt; $config-&gt;get('ecc_general.notification_hours'),
  '#description' =&gt; $this-&gt;t('what are the hours that messages should not be sent?'),
);


I have tried the Time Range and and Time Field modules. I'm able to add the time range field, but I failed to programmatically create it.
Haven't tested this but if you install time field module you then could do this to simulate a range:

$form['from'] = [
  '#type' =&gt; 'time',
  '#title' =&gt; 'from',
];
$form['to'] = [
  '#type' =&gt; 'time',
  '#title' =&gt; 'to',
];