webtrees
webtrees copied to clipboard
Show year/month/day when calculating date [Enhancement]
On facts and events, there is the "aged" information for each item such as:
August 17, 1933 (aged 19 years)
If the two dates are known precisely, it would be great to have the whole calculated difference such as:
August 17, 1933 (aged 19 years, 3 months, 15 days)
The modification of the code would be in App/Age.php:
public function __toString(): string
{
if (!$this->is_valid) {
return '';
}
if ($this->years < 0) {
return view('icons/warning');
}
if ($this->years > 0) {
$y = I18N::plural('%s year', '%s years', $this->years, I18N::number($this->years));
$m = I18N::plural('%s month', '%s months', $this->months, I18N::number($this->months));
$d = I18N::plural('%s day', '%s days', $this->days, I18N::number($this->days));
return $y . ", " . $m . ", " . $d;
From a user experience point of view, it would be very useful but sometimes it could be too much information. Ideally, you would want an option in the tree preferences to show full date difference or the current format. Or better, to keep the current format and have an overlay that shows the full difference.
Here is a proper patch that is working:
diff --git a/app/Age.php b/app/Age.php
index ccb4d8a8cf..4db962e266 100644
--- a/app/Age.php
+++ b/app/Age.php
@@ -86,17 +86,20 @@ class Age
return view('icons/warning');
}
+ $ret = "";
if ($this->years > 0) {
- return I18N::plural('%s year', '%s years', $this->years, I18N::number($this->years));
+ $ret .= I18N::plural('%s year', '%s years', $this->years, I18N::number($this->years));
}
if ($this->months > 0) {
- return I18N::plural('%s month', '%s months', $this->months, I18N::number($this->months));
+ $ret .= (strlen($ret) > 0 ? ", " : "") . I18N::plural('%s month', '%s months', $this->months, I18N::number($this->months));
}
- if ($this->days > 0 || $this->is_exact) {
- return I18N::plural('%s day', '%s days', $this->days, I18N::number($this->days));
+ if ($this->days > 0) {
+ $ret .= (strlen($ret) > 0 ? ", " : "") . I18N::plural('%s day', '%s days', $this->days, I18N::number($this->days));
}
+ if (strlen($ret) > 0)
+ return $ret;
return I18N::number(0);
}
Personally, I prefer the current solution
Beyond taste and color, I think that my patch makes some sense because it can bring useful information. For instance, I wanted to know who was the longest person to live and I had to grand-parents at 97 years both but I could really tell how longer one was surviving the other. I got the answer. I also discovered that my mom died at the exact same age minus one year of her mom (to the day).
Anyway, this is where perhaps an option in the preferences would make sense.
Perhaps just make it a hover tooltip kind of thing. Doesn't need to be displayed.