Index: trunk/core/kernel/utility/formatters/date_formatter.php =================================================================== diff -u -r5340 -r7902 --- trunk/core/kernel/utility/formatters/date_formatter.php (.../date_formatter.php) (revision 5340) +++ trunk/core/kernel/utility/formatters/date_formatter.php (.../date_formatter.php) (revision 7902) @@ -2,40 +2,86 @@ class kDateFormatter extends kFormatter { -/* function kDateFormatter() + /** + * Current Language + * + * @var LanguagesItem + */ + var $language = null; + + function kDateFormatter() { - parent::kFormatter(); - $this->ErrorMsgs['bad_dformat'] = 'Please use correct date format (%s) ex. (%s)'; + parent::kBase(); + $this->language =& $this->Application->recallObject('lang.current'); } - */ - function PrepareOptions($field_name, &$field_options, &$object) + /** + * Sets mixed format (date + time) for field if not set directly + * + * @param Array $field_options options of field + * @param Array $format separate formats for date & time + * @param string $type destination key in field_options to store mixed format + */ + function SetMixedFormat(&$field_options, &$format, $type) { - $date_format = getArrayValue($field_options, 'date_format'); - $time_format = getArrayValue($field_options, 'time_format'); + if (!isset($field_options[$type])) { + $field_options[$type] = $format['date'].$field_options['date_time_separator'].$format['time']; + } + else if(preg_match('/_regional_(.*)/', $field_options[$type], $regs)) { + $field_options[$type] = $this->language->GetDBField($regs[1]); + } + $format['mixed'] = $field_options[$type]; + } + + /** + * Returns separate formats for date,time,combined for input & display formats + * + * @param Array $field_options options of field + * @param string $type type of requested information = {mixed,date,time} + * @return Array display & input formats + */ + function GetSeparateFormats(&$field_options, $type) + { + if ($type == 'mixed') { + if (!isset($field_options['date_time_separator'])) $field_options['date_time_separator'] = ' '; + + $display_format = Array (); + $input_format = Array (); + + list ($display_format['date'], $input_format['date']) = $this->GetSeparateFormats($field_options, 'date'); + list ($display_format['time'], $input_format['time']) = $this->GetSeparateFormats($field_options, 'time'); + + $this->SetMixedFormat($field_options, $display_format, 'format'); + $this->SetMixedFormat($field_options, $input_format, 'input_format'); + + return Array ($display_format, $input_format); + } + else { + $format = getArrayValue($field_options, $type.'_format'); + if ($format === false) { + $format = $this->language->GetDBField(ucfirst($type).'Format'); + } + + $input_format = $this->language->GetDBField('Input'.ucfirst($type).'Format'); + + return Array ($format, $input_format); + } + } - $language =& $this->Application->recallObject('lang.current'); - - if ($date_format === false) $date_format = $language->GetDBField('DateFormat'); - if ($time_format === false) $time_format = $language->GetDBField('TimeFormat'); - - $input_format['date'] = $language->GetDBField('InputDateFormat'); - $input_format['time'] = $language->GetDBField('InputTimeFormat'); - - if (!isset($field_options['date_time_separator'])) $field_options['date_time_separator'] = ' '; - $field_options['format'] = $date_format.$field_options['date_time_separator'].$time_format; - $field_options['input_format'] = $input_format['date'].$field_options['date_time_separator'].$input_format['time']; - + function PrepareOptions($field_name, &$field_options, &$object) + { + list ($display_format, $input_format) = $this->GetSeparateFormats($field_options, 'mixed'); + $field_options['sub_fields'] = Array('date' => $field_name.'_date', 'time' => $field_name.'_time'); $add_fields = Array(); - $opts = Array('master_field' => $field_name, 'formatter'=>'kDateFormatter', 'format' => $date_format, 'input_format' => $input_format['date']); + $opts = Array('master_field' => $field_name, 'formatter'=>'kDateFormatter', 'format' => $display_format['date'], 'input_format' => $input_format['date']); if ( isset($field_options['default']) ) $opts['default'] = $field_options['default']; if ( isset($field_options['required']) ) $opts['required'] = $field_options['required']; $add_fields[$field_name.'_date'] = $opts; - $opts['format'] = $time_format; + $opts['format'] = $display_format['time']; $opts['input_format'] = $input_format['time']; $add_fields[$field_name.'_time'] = $opts;