Example #1
0
 function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected = null, $attributes = array(), $showEmpty = true)
 {
     if ($this->checkConfirmScreen()) {
         $args = func_get_args();
         return $this->getConfirmDatetime($fieldName, $args);
     }
     if (empty($attributes['monthNames']) && $this->monthNameSetNumber) {
         $attributes['monthNames'] = false;
     }
     $separator = !empty($attributes['separator']) ? $attributes['separator'] : '-';
     $datefmt = array('year' => $separator, 'month' => $separator, 'day' => '', 'afterDateTag' => '');
     $timefmt = array('hour' => ':', 'min' => '', 'meridian' => '');
     if (!empty($this->changeDatetimeSeparator)) {
         $datefmt = $this->changeDatetimeSeparator['datefmt'];
         $timefmt = $this->changeDatetimeSeparator['timefmt'];
     }
     $out = $out_date = $out_time = null;
     if (!empty($dateFormat) && $dateFormat !== 'NONE') {
         $tmp_separator = !empty($attributes['separator']) ? $attributes['separator'] : null;
         $attributes['separator'] = '__/__';
         $out_date = parent::datetime($fieldName, $dateFormat, 'NONE', $selected, $attributes, $showEmpty);
         $attributes['separator'] = $tmp_separator;
     }
     if (!empty($timeFormat) && $timeFormat !== 'NONE') {
         $out_time = parent::datetime($fieldName, 'NONE', $timeFormat, $selected, $attributes, $showEmpty);
     }
     if (!empty($out_date)) {
         $pattern = '#^(.+?)__/__(.+?)__/__(.+?)$#is';
         $out .= preg_replace($pattern, '$1' . $datefmt['year'] . ' $2' . $datefmt['month'] . ' $3' . $datefmt['day'], $out_date);
         $out .= $datefmt['afterDateTag'];
     }
     if (!empty($out_time) && $timeFormat == 24) {
         $pattern = '#^<select(.*?)</select>:<select(.*?)$#is';
         $replace = '<select$1</select>' . $timefmt['hour'] . ' <select$2' . $timefmt['min'];
         $out .= preg_replace($pattern, $replace, $out_time);
     }
     if (!empty($out_time) && $timeFormat == 12) {
         $pattern = '#^<select(.*?)</select>:<select(.*?)</select> <select(.*?)$#is';
         $replace = '<select$1</select>' . $timefmt['hour'] . ' <select$2</select>' . $timefmt['min'] . '<select$3';
         $out .= preg_replace($pattern, $replace, $out_time);
     }
     return $out;
 }
Example #2
0
 public function testDatetime()
 {
     $this->assertEqual(FormHelper::datetime('name', 'empty', range('2010', '2015'), array('class' => 'myClass')), '<select name="_name_day" class="myClass" id="_name_day">' . '<option value="01">01</option>' . '<option value="02">02</option>' . '<option value="03">03</option>' . '<option value="04">04</option>' . '<option value="05">05</option>' . '<option value="06">06</option>' . '<option value="07">07</option>' . '<option value="08">08</option>' . '<option value="09">09</option>' . '<option value="10">10</option>' . '<option value="11">11</option>' . '<option value="12">12</option>' . '<option value="13">13</option>' . '<option value="14">14</option>' . '<option value="15">15</option>' . '<option value="16">16</option>' . '<option value="17">17</option>' . '<option value="18">18</option>' . '<option value="19">19</option>' . '<option value="20">20</option>' . '<option value="21">21</option>' . '<option value="22">22</option>' . '<option value="23">23</option>' . '<option value="24">24</option>' . '<option value="25">25</option>' . '<option value="26">26</option>' . '<option value="27">27</option>' . '<option value="28">28</option>' . '<option value="29">29</option>' . '<option value="30">30</option>' . '<option value="31">31</option>' . '</select> / ' . '<select name="_name_month" class="myClass" id="_name_month">' . '<option value="01">janvier</option>' . '<option value="02">février</option>' . '<option value="03">mars</option>' . '<option value="04">avril</option>' . '<option value="05">mai</option>' . '<option value="06">juin</option>' . '<option value="07">juillet</option>' . '<option value="08">août</option>' . '<option value="09">septembre</option>' . '<option value="10">octobre</option>' . '<option value="11">novembre</option>' . '<option value="12">décembre</option>' . '</select> / ' . '<select name="_name_year" class="myClass" id="_name_year">' . '<option value="2010">2010</option>' . '<option value="2011">2011</option>' . '<option value="2012">2012</option>' . '<option value="2013">2013</option>' . '<option value="2014">2014</option>' . '<option value="2015">2015</option>' . '</select> à ' . '<input type="text" name="_name_hour" size="2" maxlength="2" id="_name_hour">' . ' : ' . '<input type="text" name="_name_minutes" size="2" maxlength="2" id="_name_minutes">' . '<input type="hidden" name="_name_seconds" id="_name_seconds">');
     $this->assertEqual(FormHelper::datetime('name', 'empty', range('2010', '2015'), array('class' => 'myClass', 'seconds' => true)), '<select name="_name_day" class="myClass" id="_name_day">' . '<option value="01">01</option>' . '<option value="02">02</option>' . '<option value="03">03</option>' . '<option value="04">04</option>' . '<option value="05">05</option>' . '<option value="06">06</option>' . '<option value="07">07</option>' . '<option value="08">08</option>' . '<option value="09">09</option>' . '<option value="10">10</option>' . '<option value="11">11</option>' . '<option value="12">12</option>' . '<option value="13">13</option>' . '<option value="14">14</option>' . '<option value="15">15</option>' . '<option value="16">16</option>' . '<option value="17">17</option>' . '<option value="18">18</option>' . '<option value="19">19</option>' . '<option value="20">20</option>' . '<option value="21">21</option>' . '<option value="22">22</option>' . '<option value="23">23</option>' . '<option value="24">24</option>' . '<option value="25">25</option>' . '<option value="26">26</option>' . '<option value="27">27</option>' . '<option value="28">28</option>' . '<option value="29">29</option>' . '<option value="30">30</option>' . '<option value="31">31</option>' . '</select> / ' . '<select name="_name_month" class="myClass" id="_name_month">' . '<option value="01">janvier</option>' . '<option value="02">février</option>' . '<option value="03">mars</option>' . '<option value="04">avril</option>' . '<option value="05">mai</option>' . '<option value="06">juin</option>' . '<option value="07">juillet</option>' . '<option value="08">août</option>' . '<option value="09">septembre</option>' . '<option value="10">octobre</option>' . '<option value="11">novembre</option>' . '<option value="12">décembre</option>' . '</select> / ' . '<select name="_name_year" class="myClass" id="_name_year">' . '<option value="2010">2010</option>' . '<option value="2011">2011</option>' . '<option value="2012">2012</option>' . '<option value="2013">2013</option>' . '<option value="2014">2014</option>' . '<option value="2015">2015</option>' . '</select> à ' . '<input type="text" name="_name_hour" size="2" maxlength="2" id="_name_hour">' . ' : ' . '<input type="text" name="_name_minutes" size="2" maxlength="2" id="_name_minutes">' . ' : ' . '<input type="text" name="_name_seconds" size="2" maxlength="2" id="_name_seconds">');
 }