Changeset View
Changeset View
Standalone View
Standalone View
core/kernel/utility/formatters/date_formatter.php
Show All 18 Lines | |||||
/** | /** | ||||
* Current Language | * Current Language | ||||
* | * | ||||
* @var LanguagesItem | * @var LanguagesItem | ||||
*/ | */ | ||||
var $language = null; | var $language = null; | ||||
/** | /** | ||||
* Date helper. | |||||
* | |||||
* @var DateHelper | |||||
*/ | |||||
protected $dateHelper; | |||||
/** | |||||
* Create date formatter | * Create date formatter | ||||
* | * | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
parent::__construct(); | parent::__construct(); | ||||
$this->language = $this->Application->recallObject('lang.current'); | $this->language = $this->Application->recallObject('lang.current'); | ||||
} | } | ||||
alex: Actually please use lazy loading like so:
# remove this line
# on top of `RelativeFormat`… | |||||
/** | /** | ||||
* Sets mixed format (date + time) for field if not set directly | * Sets mixed format (date + time) for field if not set directly | ||||
* | * | ||||
* @param Array $field_options options of field | * @param Array $field_options options of field | ||||
* @param Array $format separate formats for date & time | * @param Array $format separate formats for date & time | ||||
* @param string $type destination key in field_options to store mixed format | * @param string $type destination key in field_options to store mixed format | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Line(s) | |||||
$options['format'] = $this->language->GetDBField($regs[1]); | $options['format'] = $this->language->GetDBField($regs[1]); | ||||
} | } | ||||
if ( $options['format'] == '_input_' ) { | if ( $options['format'] == '_input_' ) { | ||||
// use input format instead of output format | // use input format instead of output format | ||||
$options['format'] = $options['input_format']; | $options['format'] = $options['input_format']; | ||||
} | } | ||||
if ( !$options['use_timezone'] ) { | if ( !$options['use_timezone'] ) { | ||||
Not Done ReplyNot sure why, but when I apply the patch this fragment is added into Parse method instead of Format method. Probably will be fixed when you resend the patch. alex: Not sure why, but when I apply the patch this fragment is added into `Parse` method instead of… | |||||
return gmdate($options['format'], $value); | return gmdate($options['format'], $value); | ||||
} | } | ||||
$format = defined($options['format']) ? constant($options['format']) : $options['format']; | $format = defined($options['format']) ? constant($options['format']) : $options['format']; | ||||
$dt_separator = getArrayValue($options, 'date_time_separator'); | $dt_separator = getArrayValue($options, 'date_time_separator'); | ||||
if ( $dt_separator ) { | if ( $dt_separator ) { | ||||
$format = trim($format, $dt_separator); | $format = trim($format, $dt_separator); | ||||
} | } | ||||
if ( preg_match('/^relative(.*)/', $options['format'], $regs) ) { | |||||
$detalization_level = trim($regs[1], ':'); | |||||
return $this->relativeFormat($value, ($detalization_level < 1) ? 1 : $detalization_level); | |||||
} | |||||
return date($format, $value); | return date($format, $value); | ||||
} | } | ||||
/** | |||||
* Formats value as relation to current time. | |||||
* | |||||
* @param integer $from Date. | |||||
* @param integer $level_of_detail Level of details. | |||||
* | |||||
* @return string | |||||
*/ | |||||
protected function relativeFormat($from, $level_of_detail) | |||||
Not Done Reply
alex: # add `DateHelper` class
# add `kDateFormatter::dateHelper` protected property
# in… | |||||
Not Done ReplyPlease:
alex: Please:
# rename method from `RelativeFormat` to `relativeFormat`
# change `detalization_level`… | |||||
{ | |||||
if ( !isset($this->dateHelper) ) { | |||||
$this->dateHelper = $this->Application->recallObject('DateHelper'); | |||||
} | |||||
if ( $from == TIMENOW ) { | |||||
$from = TIMENOW - 1; | |||||
} | |||||
$suffix = $this->Application->Phrase($from > TIMENOW ? 'lc_since' : 'lc_ago'); | |||||
$res = $this->dateHelper->getHumanTime(abs($from - TIMENOW), $level_of_detail); | |||||
return $res . ' ' . $suffix; | |||||
} | |||||
function HumanFormat($format) | function HumanFormat($format) | ||||
Missing doc comment for function HumanFormat() Lint: CodingStandard.Commenting.FunctionComment.Missing: Missing doc comment for function HumanFormat() | |||||
Lint: Squiz.Scope.MethodScope.Missing: Visibility must be declared on method "HumanFormat" | |||||
Method name "kDateFormatter::HumanFormat" is not in camel caps format Lint: CodingStandard.NamingConventions.ValidFunctionName.NotCamelCaps: Method name "kDateFormatter::HumanFormat" is not in camel caps format | |||||
{ | { | ||||
$patterns = Array('/m/', | $patterns = Array('/m/', | ||||
'/n/', | '/n/', | ||||
'/d/', | '/d/', | ||||
'/j/', | '/j/', | ||||
'/y/', | '/y/', | ||||
'/Y/', | '/Y/', | ||||
'/h|H/', | '/h|H/', | ||||
'/g|G/', | '/g|G/', | ||||
'/i/', | '/i/', | ||||
'/s/', | '/s/', | ||||
'/a|A/'); | '/a|A/'); | ||||
$replace = Array( 'mm', | $replace = Array( 'mm', | ||||
'm', | 'm', | ||||
'dd', | 'dd', | ||||
'd', | 'd', | ||||
Not Done Replybecomes: $res = $this->dateHelper->getHumanTime(abs($from - TIMENOW), detalization_level); alex: becomes:
```
lang=php
$res = $this->dateHelper->getHumanTime(abs($from - TIMENOW)… | |||||
'yy', | 'yy', | ||||
'yyyy', | 'yyyy', | ||||
'hh', | 'hh', | ||||
'h', | 'h', | ||||
Not Done Replybecomes: return $res . ' ' . $suffix; alex: becomes:
```
lang=php
return $res . ' ' . $suffix;
``` | |||||
'mm', | 'mm', | ||||
'ss', | 'ss', | ||||
'AM'); | 'AM'); | ||||
$res = preg_replace($patterns, $replace, $format); | $res = preg_replace($patterns, $replace, $format); | ||||
return $res; | return $res; | ||||
} | } | ||||
function SQLFormat($format) | function SQLFormat($format) | ||||
▲ Show 20 Lines • Show All 204 Lines • Show Last 20 Lines |
Actually please use lazy loading like so:
This would also solve recursion issue, when rebuilding classmap.