# Preparation
* in IDE
1. open `core/admin_templates/users/users_edit.tpl` file for editing
2. add these lines after `<inp2:m_RenderElement name="combined_header" ...` line:
```
lang=html
<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/>
```
3. save changes
4. open `core/units/users/users_tag_processor.php` file for editing
5. add this method/tag in there:
```
lang=php
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']);
}
```
6. 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
1. go to {nav Configuration > Website > Regional} section
2. import `core/install/english.lang` language pack (to add new phrases)
# Testing `kDateFormatter`
1. Login to `Admin console`
2. Go to {nav User Management > Users}
3. Open any user for editing
4. change the `Created On` field to be 2 years and some days in the past
5. Save changes
6. Open the same user for editing
7. 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
```
8. change the `Created On` field to be 2 years and some days in the future
9. Save changes
10. Open the same user for editing
11. 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
```
# Testing `DateHelper::getShortHumanTime()`
1. Add method into the end of `PhraseTagProcessor` class in `core/units/phrases/phrase_tp.php`:
``` lang=php, name=core/units/phrases/phrase_tp.php
protected function RelatedModifiedOn($params)
{
/** @var kDBItem $object */
$object = $this->getObject($params);
/** @var DateHelper $date_helper */
$date_helper = $this->Application->recallObject('DateHelper');
return $date_helper->getShortHumanTime(TIMENOW - $object->GetDBField('LastChanged'));
}
```
2. Add tag into `core/admin_templates/languages/phrase_edit.tpl` just before `<div id="scroll_container">`:
``` lang=html, name=core/admin_templates/languages/phrase_edit.tpl
<inp2:phrases_RelatedModifiedOn/>
```
3. Go to admin console, {nav Website & Content > Labels & Phrases}
4. Select some phrase, note it's `Modified On` time and click Edit
5. Confirm you see relative time like `3d 17h 22mi 43s` just under header. It should correspond to noted `Modified On`===<br/>
<inp2:u_ShortHumanTimeTests/>
```
3. save changes
4. open `core/units/users/users_tag_processor.php` file for editing
5. add this method/tag in there:
```
lang=php
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/>';
}
```
6. 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
1. go to {nav Configuration > Website > Regional} section
2. import `core/install/english.lang` language pack (to add new phrases)
# Testing
1. Login to `Admin console`
2. Go to {nav User Management > Users}
3. Open any user for editing
4. change the `Created On` field to be 2 years and some days in the past
5. Save changes
6. Open the same user for editing
7. 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
```
8. change the `Created On` field to be 2 years and some days in the future
9. Save changes
10. Open the same user for editing
11. 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
```
12. 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