Skip to content

Commit 8ee052d

Browse files
committed
FactResolver: compact dd.mm.yyyy dates and full place name
formatDate() returns DD.MM.YYYY when day, month, and year are known, falling back to MM.YYYY / YYYY for partial precision and to the locale-aware display() for qualified dates (ABT/BEF/AFT/FROM..TO) so the qualifier prefix stays visible. Approximate dates collapsed to a bare minimumDate would silently drop "ABT". Place column now uses gedcomName() instead of shortName() to mirror the fan-chart tooltip — the renderer in pedigree-chart truncates the rendered string to row width and exposes the full hierarchy via <title> on hover.
1 parent 2d0e817 commit 8ee052d

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

src/Processor/FactResolver.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace MagicSunday\Webtrees\ModuleBase\Processor;
1313

14+
use Fisharebest\Webtrees\Date;
1415
use Fisharebest\Webtrees\Fact;
1516
use Fisharebest\Webtrees\Gedcom;
1617
use Fisharebest\Webtrees\Individual;
@@ -149,12 +150,50 @@ private function firstWithTag(Individual $individual, string $tag): ?array
149150
return [
150151
'tag' => $tag,
151152
'label' => $fact->label(),
152-
'date' => strip_tags($fact->date()->display()),
153-
'place' => strip_tags($fact->place()->shortName()),
153+
'date' => $this->formatDate($fact->date()),
154+
// Full GEDCOM place name (mirrors the fan-chart tooltip). The
155+
// renderer truncates the visible text to the available row
156+
// width and exposes the full string via <title> so hovering a
157+
// truncated row reveals the complete place hierarchy.
158+
'place' => $fact->place()->gedcomName(),
154159
'value' => strip_tags($fact->value()),
155160
];
156161
}
157162

163+
/**
164+
* Formats a fact date as DD.MM.YYYY when day, month, and year are all
165+
* known, falling back to MM.YYYY or YYYY for partial precision, and to
166+
* the locale-aware display for approximate / qualified dates ("ABT
167+
* 1832", "BEF 1900"). Matches the compact format used in the fan-chart
168+
* tooltip so the chart-box rows stay narrow enough to show place
169+
* alongside the date.
170+
*/
171+
private function formatDate(Date $date): string
172+
{
173+
// Approximate / qualified dates (ABT, BEF, AFT, FROM..TO, …) keep
174+
// the locale-aware display so the qualifier prefix stays visible.
175+
// Collapsing them to bare minimumDate would silently drop "ABT".
176+
if (!$date->isOK() || $date->qual1 !== '' || $date->qual2 !== '') {
177+
return strip_tags($date->display());
178+
}
179+
180+
$cd = $date->minimumDate();
181+
182+
if ($cd->day() > 0 && $cd->month() > 0) {
183+
return $cd->format('%d.%m.%Y');
184+
}
185+
186+
if ($cd->month() > 0) {
187+
return $cd->format('%m.%Y');
188+
}
189+
190+
if ($cd->year() > 0) {
191+
return $cd->format('%Y');
192+
}
193+
194+
return strip_tags($date->display());
195+
}
196+
158197
/**
159198
* Placeholder used in {@see effectiveTags()} so the BIRT row's position
160199
* is preserved regardless of which concrete birth-equivalent tag each

0 commit comments

Comments
 (0)