Preparation
- in IDE
- open core/admin_templates/users/users_edit.tpl file for editing
- add these lines after <inp2:m_RenderElement name="combined_header" ... line:
<inp2:u_Field name="CreatedOn" format="relative"/><br/> <inp2:u_Field name="CreatedOn" format="relative:1"/><br/> <inp2:u_Field name="CreatedOn" format="relative:2"/><br/> <inp2:u_Field name="CreatedOn" format="relative:3"/><br/> <inp2:u_Field name="CreatedOn" format="relative:4"/><br/> <inp2:u_Field name="CreatedOn" format="relative:5"/><br/> <inp2:u_Field name="CreatedOn" format="relative:6"/><br/> <inp2:u_Field name="CreatedOn" format="relative:7"/><br/> ---<br/> <inp2:u_RelatedCreatedOn level="1"/><br/> <inp2:u_RelatedCreatedOn level="2"/><br/> <inp2:u_RelatedCreatedOn level="3"/><br/> <inp2:u_RelatedCreatedOn level="4"/><br/> <inp2:u_RelatedCreatedOn level="5"/><br/> <inp2:u_RelatedCreatedOn level="6"/><br/> <inp2:u_RelatedCreatedOn level="7"/><br/> ===<br/> <inp2:u_ShortHumanTimeTests/>
- save changes
- open core/units/users/users_tag_processor.php file for editing
- add this method/tag in there:
protected function RelatedCreatedOn(array $params) { /** @var kDBItem $object */ $object = $this->getObject($params); /** @var DateHelper $date_helper */ $date_helper = $this->Application->recallObject('DateHelper'); return $date_helper->getHumanTime(abs($object->GetDBField('CreatedOn') - TIMENOW), $params['level']); } protected function ShortHumanTimeTests($params) { /** @var DateHelper $date_helper */ $date_helper = $this->Application->recallObject('DateHelper'); $tests = array( $date_helper->getShortHumanTime(TIMENOW - strtotime('-1 year')), $date_helper->getShortHumanTime(TIMENOW - strtotime('-1 year -2 months')), $date_helper->getShortHumanTime(TIMENOW - strtotime('-1 year -2 months -3 days')), $date_helper->getShortHumanTime(TIMENOW - strtotime('-1 year -2 months -3 days -4 hours')), $date_helper->getShortHumanTime(TIMENOW - strtotime('-1 year -2 months -3 days -4 hours -5 minutes')), $date_helper->getShortHumanTime(TIMENOW - strtotime('-1 year -2 months -3 days -4 hours -5 minutes -6 seconds')), ); return implode('<br/>', $tests) . '<br/>'; }
- save changes
- in CLI:
- run the ./in-portal classmap:rebuild command in the root folder of a project (for new PHP classes to be recognized)
- in Admin Console
- go to Configuration → Website → Regional section
- import core/install/english.lang language pack (to add new phrases)
Testing
- Login to Admin console
- Go to User Management → Users
- Open any user for editing
- change the Created On field to be 2 years and some days in the past
- Save changes
- Open the same user for editing
- Confirm, that below the blue bar you'll see this (do the math yourself to confirm, that shown values are correct):
2 years ago 2 years ago 2 years, 7 months ago 2 years, 7 months, 3 weeks ago 2 years, 7 months, 3 weeks, 1 day ago 2 years, 7 months, 3 weeks, 1 day, 21 hours ago 2 years, 7 months, 3 weeks, 1 day, 21 hours, 17 minutes ago 2 years, 7 months, 3 weeks, 1 day, 21 hours, 17 minutes, and 36 seconds ago --- 2 years 2 years 2 years, 7 months 2 years, 7 months, 3 weeks 2 years, 7 months, 3 weeks, 1 day 2 years, 7 months, 3 weeks, 1 day, 21 hours 2 years, 7 months, 3 weeks, 1 day, 21 hours, 17 minutes 2 years, 7 months, 3 weeks, 1 day, 21 hours, 17 minutes, and 36 seconds === 1y 1y 2m 2d 1y 2m 5d 1y 2m 5d 4h 1y 2m 5d 4h 5mi 1y 2m 5d 4h 5mi 6s
- change the Created On field to be 2 years and some days in the future
- Save changes
- Open the same user for editing
- Confirm, that below the blue bar you'll see this (do the math yourself to confirm, that shown values are correct):
since 1 year since 1 year since 1 year, 8 months since 1 year, 8 months, 1 week since 1 year, 8 months, 1 week, 3 days since 1 year, 8 months, 1 week, 3 days, 2 hours since 1 year, 8 months, 1 week, 3 days, 2 hours, 38 minutes since 1 year, 8 months, 1 week, 3 days, 2 hours, 38 minutes, and 49 seconds --- 1 year 1 year 1 year, 8 months 1 year, 8 months, 1 week 1 year, 8 months, 1 week, 3 days 1 year, 8 months, 1 week, 3 days, 2 hours 1 year, 8 months, 1 week, 3 days, 2 hours, 38 minutes 1 year, 8 months, 1 week, 3 days, 2 hours, 38 minutes, and 49 seconds === 1y 1y 2m 2d 1y 2m 5d 1y 2m 5d 4h 1y 2m 5d 4h 5mi 1y 2m 5d 4h 5mi 6s
- in the output after === logic is like this: the number at each position is larger by 1 than in the previous position (month is larger by 1 than year, the day is larger by 1 than month and so on), but the number of days won't be 2d as expected, because day count in month differs