Index: core/install/cache/class_structure.php
===================================================================
--- core/install/cache/class_structure.php
+++ core/install/cache/class_structure.php
@@ -44,6 +44,7 @@
'CustomDataEventHandler' => '/core/units/custom_data/custom_data_event_handler.php',
'CustomFieldsEventHandler' => '/core/units/custom_fields/custom_fields_event_handler.php',
'CustomFieldsTagProcessor' => '/core/units/custom_fields/custom_fields_tag_processor.php',
+ 'DateHelper' => '/core/units/helpers/date_helper.php',
'Debugger' => '/core/kernel/utility/debugger.php',
'DebuggerUtil' => '/core/kernel/utility/debugger.php',
'DeploymentHelper' => '/core/units/helpers/deployment_helper.php',
@@ -604,6 +605,13 @@
0 => 'kDBTagProcessor',
),
),
+ 'DateHelper' => array(
+ 'type' => 1,
+ 'modifiers' => 0,
+ 'extends' => array(
+ 0 => 'kHelper',
+ ),
+ ),
'Debugger' => array(
'type' => 1,
'modifiers' => 0,
Index: core/install/english.lang
===================================================================
--- core/install/english.lang
+++ core/install/english.lang
@@ -1747,6 +1747,7 @@
V2luZG93cw==
eWVhcg==
WWVz
+ YWdv
U3ViLXNlY3Rpb25zIFF1YW50aXR5
TmF2aWdhdGlvbiBCYXI=
UmF0aW5n
@@ -1779,6 +1780,7 @@
SXRlbSBJcyBhIFRvcCBTZWxsZXI=
VVJM
b2Y=
+ c2luY2U=
SW52YWxpZA==
Tm90IFZhbGlkYXRlZA==
VmFsaWQ=
Index: core/kernel/utility/formatters/date_formatter.php
===================================================================
--- core/kernel/utility/formatters/date_formatter.php
+++ core/kernel/utility/formatters/date_formatter.php
@@ -24,6 +24,13 @@
var $language = null;
/**
+ * Date helper.
+ *
+ * @var DateHelper
+ */
+ protected $dateHelper;
+
+ /**
* Create date formatter
*
* @access public
@@ -33,6 +40,7 @@
parent::__construct();
$this->language = $this->Application->recallObject('lang.current');
+ $this->dateHelper = $this->Application->recallObject('DateHelper');
}
/**
@@ -264,6 +272,12 @@
$options['format'] = $options['input_format'];
}
+ if ( preg_match('/^relative(.*)/', $options['format'], $regs) ) {
+ $detalization_level = trim($regs[1], ':');
+
+ return $this->RelativeFormat($value, ($detalization_level < 1) ? 1 : $detalization_level);
+ }
+
if (!$options['use_timezone']) {
return gmdate($options['format'], $value);
}
@@ -278,6 +292,26 @@
return date($format, $value);
}
+ /**
+ * Formats value as relation to current time;
+ *
+ * @param integer $from Date.
+ * @param integer $detalization_level Detalization level.
+ *
+ * @return string
+ */
+ protected function RelativeFormat($from, $detalization_level)
+ {
+ if ( $from == TIMENOW ) {
+ $from = TIMENOW - 1;
+ }
+
+ $suffix = $this->Application->Phrase($from > TIMENOW ? 'lc_since' : 'lc_ago');
+ $res = $this->dateHelper->getHumanTime(abs($from - TIMENOW), $detalization_level);
+
+ return $res . ' ' . $suffix;
+ }
+
function HumanFormat($format)
{
$patterns = Array('/m/',
@@ -506,4 +540,4 @@
{
return $this->Format( time(), $field, $object, $options['input_format']);
}
-}
\ No newline at end of file
+}
Index: core/units/helpers/date_helper.php
===================================================================
--- /dev/null
+++ core/units/helpers/date_helper.php
@@ -0,0 +1,46 @@
+ 29030400, // Seconds in a year (12 months).
+ 'month' => 2419200, // Seconds in a month (4 weeks).
+ 'week' => 604800, // Seconds in a week (7 days).
+ 'day' => 86400, // Seconds in a day (24 hours).
+ 'hour' => 3600, // Seconds in an hour (60 minutes).
+ 'minute' => 60, // Seconds in a minute (60 seconds).
+ 'second' => 1, // 1 second.
+ );
+
+ $res = '';
+ $current_detalization_level = 0;
+
+ foreach ( $units as $unit => $multiplier ) {
+ if ( $seconds >= $multiplier ) {
+ $and = (!$res || $multiplier != 1) ? '' : 'and ';
+ $res .= ', ' . $and . intval($seconds / $multiplier);
+ $res .= ' ' . $unit . (intval($seconds / $multiplier) == 1 ? '' : 's');
+ $seconds -= intval($seconds / $multiplier) * $multiplier;
+ $current_detalization_level++;
+
+ if ( $current_detalization_level >= $detalization_level ) {
+ break;
+ }
+ }
+ }
+
+ return substr($res, strlen(', '));
+ }
+
+}