-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathevent_node.go
73 lines (62 loc) · 1.74 KB
/
event_node.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
package gedcom
// EventNode is a noteworthy happening related to an individual, a group, or an
// organization.
type EventNode struct {
*SimpleNode
}
// EventNode creates a new EVEN node.
func NewEventNode(value string, children ...Node) *EventNode {
return &EventNode{
newSimpleNode(TagEvent, value, "", children...),
}
}
// Dates returns zero or more dates associated with the event.
//
// When more than one date is returned you should not assume that the order has
// any significance for the importance of the dates.
//
// If the node is nil the result will also be nil.
func (node *EventNode) Dates() DateNodes {
return Dates(node)
}
// Equal tests if two events are the same.
//
// Two events are considered equal if:
//
// 1. They both contain the same date. If either or both contain more than one
// date only a single date must match both sides.
//
// 2. They both do not have any dates, but all other attributes are the same.
//
// If either node is nil (including both) or if the right side is not a
// EventNode then false is always returned.
func (node *EventNode) Equals(node2 Node) bool {
if IsNil(node) {
return false
}
if IsNil(node2) {
return false
}
if n2, ok := node2.(*EventNode); ok {
leftDates := node.Dates()
rightDates := n2.Dates()
for _, left := range leftDates {
for _, right := range rightDates {
if left.Equals(right) {
return true
}
}
}
if len(leftDates) == 0 && len(rightDates) == 0 && node.Value() == node2.Value() {
return DeepEqualNodes(node.Nodes(), node2.Nodes())
}
}
return false
}
// Years returns the Years value of the minimum date node in the node.
func (node *EventNode) Years() float64 {
if min := node.Dates().Minimum(); min != nil {
return Years(min)
}
return 0
}