-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqualification.go
103 lines (73 loc) · 2.21 KB
/
qualification.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package level2
import (
"github.com/sfomuseum/go-edtf"
"github.com/sfomuseum/go-edtf/common"
"github.com/sfomuseum/go-edtf/re"
)
/*
Group Qualification
A qualification character to the immediate right of a component applies to that component as well as to all components to the left.
Example 1 ‘2004-06-11%’
year, month, and day uncertain and approximate
Example 2 ‘2004-06~-11’
year and month approximate
Example 3 ‘2004?-06-11’
year uncertain
*/
func IsGroupQualification(edtf_str string) bool {
return re.GroupQualification.MatchString(edtf_str)
}
func ParseGroupQualification(edtf_str string) (*edtf.EDTFDate, error) {
/*
GROUP 2004-06-11% 7 2004-06-11%,2004,,06,,11,%
GROUP 2004-06~-11 7 2004-06~-11,2004,,06,~,11,
GROUP 2004?-06-11 7 2004?-06-11,2004,?,06,,11,
*/
if !re.GroupQualification.MatchString(edtf_str) {
return nil, edtf.Invalid(GROUP_QUALIFICATION, edtf_str)
}
sp, err := common.DateSpanFromEDTF(edtf_str)
if err != nil {
return nil, err
}
d := &edtf.EDTFDate{
Start: sp.Start,
End: sp.End,
EDTF: edtf_str,
Level: LEVEL,
Feature: GROUP_QUALIFICATION,
}
return d, nil
}
/*
Qualification of Individual Component
A qualification character to the immediate left of a component applies to that component only.
Example 4 ‘?2004-06-~11’
year uncertain; month known; day approximate
Example 5 ‘2004-%06-11’
month uncertain and approximate; year and day known
*/
func IsIndividualQualification(edtf_str string) bool {
return re.IndividualQualification.MatchString(edtf_str)
}
func ParseIndividualQualification(edtf_str string) (*edtf.EDTFDate, error) {
/*
INDIVIDUAL ?2004-06-~11 7 ?2004-06-~11,?,2004,,06,~,11
INDIVIDUAL 2004-%06-11 7 2004-%06-11,,2004,%,06,,11
*/
if !re.IndividualQualification.MatchString(edtf_str) {
return nil, edtf.Invalid(INDIVIDUAL_QUALIFICATION, edtf_str)
}
sp, err := common.DateSpanFromEDTF(edtf_str)
if err != nil {
return nil, err
}
d := &edtf.EDTFDate{
Start: sp.Start,
End: sp.End,
EDTF: edtf_str,
Level: LEVEL,
Feature: INDIVIDUAL_QUALIFICATION,
}
return d, nil
}