-
Notifications
You must be signed in to change notification settings - Fork 20
/
individual_dates.go
79 lines (62 loc) 路 1.79 KB
/
individual_dates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package html
import (
"github.com/elliotchance/gedcom"
"github.com/elliotchance/gedcom/html/core"
"io"
)
type IndividualDates struct {
individual *gedcom.IndividualNode
visibility LivingVisibility
}
func NewIndividualDates(individual *gedcom.IndividualNode, visibility LivingVisibility) *IndividualDates {
return &IndividualDates{
individual: individual,
visibility: visibility,
}
}
func (c *IndividualDates) IsBlank() bool {
eventDates := c.EventDates()
for _, eventDate := range eventDates {
if !eventDate.IsBlank() {
return false
}
}
return true
}
func (c *IndividualDates) WriteHTMLTo(w io.Writer) (int64, error) {
isLiving := c.individual != nil && c.individual.IsLiving()
if isLiving && c.visibility == LivingVisibilityHide {
return writeNothing()
}
if isLiving && c.visibility == LivingVisibilityPlaceholder {
return core.NewText("living").WriteHTMLTo(w)
}
eventDates := c.EventDates()
return NewEventDates(eventDates).WriteHTMLTo(w)
}
func (c *IndividualDates) EventDates() []*EventDate {
eventDates := []*EventDate{}
// Use birth or fallback to baptism.
births := c.individual.Births()
baptisms := c.individual.Baptisms()
switch {
case len(births) > 0:
eventDate := NewEventDate("b.", births[0].Dates())
eventDates = append(eventDates, eventDate)
case len(baptisms) > 0:
eventDate := NewEventDate("bap.", baptisms[0].Dates())
eventDates = append(eventDates, eventDate)
}
// Use death or fallback to burial.
deaths := c.individual.Deaths()
burials := c.individual.Burials()
switch {
case len(deaths) > 0:
eventDate := NewEventDate("d.", deaths[0].Dates())
eventDates = append(eventDates, eventDate)
case len(burials) > 0:
eventDate := NewEventDate("bur.", burials[0].Dates())
eventDates = append(eventDates, eventDate)
}
return eventDates
}