/**
  * Helper method for converting from FormHelper options data to widget format.
  *
  * @param array $options Options to convert.
  * @return array Converted options.
  */
 protected function _datetimeOptions($options)
 {
     foreach ($this->_datetimeParts as $type) {
         if (!isset($options[$type])) {
             $options[$type] = [];
         }
         // Pass empty options to each type.
         if (!empty($options['empty']) && is_array($options[$type])) {
             $options[$type]['empty'] = $options['empty'];
         }
         // Move empty options into each type array.
         if (isset($options['empty'][$type])) {
             $options[$type]['empty'] = $options['empty'][$type];
         }
     }
     unset($options['empty']);
     $hasYear = is_array($options['year']);
     if ($hasYear && isset($options['minYear'])) {
         $options['year']['start'] = $options['minYear'];
     }
     if ($hasYear && isset($options['maxYear'])) {
         $options['year']['end'] = $options['maxYear'];
     }
     if ($hasYear && isset($options['orderYear'])) {
         $options['year']['order'] = $options['orderYear'];
     }
     unset($options['minYear'], $options['maxYear'], $options['orderYear']);
     if (is_array($options['month'])) {
         $options['month']['names'] = $options['monthNames'];
     }
     unset($options['monthNames']);
     if (is_array($options['hour']) && isset($options['timeFormat'])) {
         $options['hour']['format'] = $options['timeFormat'];
     }
     unset($options['timeFormat']);
     if (is_array($options['minute'])) {
         $options['minute']['interval'] = $options['interval'];
         $options['minute']['round'] = $options['round'];
     }
     unset($options['interval'], $options['round']);
     if (!isset($options['val'])) {
         $val = new IntlDateTime(null, null, 'persian');
         $currentYear = $val->format('Y');
         if (isset($options['year']['end']) && $options['year']['end'] < $currentYear) {
             $val->set($val->format($options['year']['end'] . '/MM/dd'));
         }
         $options['val'] = $val;
     }
     return $options;
 }
 /**
  * Generates a year select
  *
  * @param array $options Options list.
  * @param \Cake\View\Form\ContextInterface $context The current form context.
  * @return string
  */
 protected function _yearSelect($options, $context)
 {
     $date = new IntlDateTime(null, null, 'persian');
     $options += ['name' => '', 'val' => null, 'start' => $date->format('Y') - 5, 'end' => $date->format('Y') + 5, 'order' => 'desc', 'options' => []];
     if (!empty($options['val'])) {
         $options['start'] = min($options['val'], $options['start']);
         $options['end'] = max($options['val'], $options['end']);
     }
     if (empty($options['options'])) {
         $options['options'] = $this->_generateNumbers($options['start'], $options['end']);
     }
     if ($options['order'] === 'desc') {
         $options['options'] = array_reverse($options['options'], true);
     }
     unset($options['start'], $options['end'], $options['order']);
     return $this->_select->render($options, $context);
 }
 function testSetDate()
 {
     $date = new IntlDateTime('yesterday');
     $date->setDate(2009, 1, 15);
     $result = $date->format('yyyy/MM/dd HH:mm:ss');
     $this->assertEquals($result, '2009/01/15 00:00:00');
 }