-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunspecified_digit.go
67 lines (51 loc) · 1.46 KB
/
unspecified_digit.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
package level2
import (
"github.com/sfomuseum/go-edtf"
"github.com/sfomuseum/go-edtf/common"
"github.com/sfomuseum/go-edtf/re"
// "strconv"
// "strings"
)
/*
Unspecified Digit
For level 2 the unspecified digit, 'X', may occur anywhere within a component.
Example 1 ‘156X-12-25’
December 25 sometime during the 1560s
Example 2 ‘15XX-12-25’
December 25 sometime during the 1500s
Example 3 ‘XXXX-12-XX’
Some day in December in some year
Example 4 '1XXX-XX’
Some month during the 1000s
Example 5 ‘1XXX-12’
Some December during the 1000s
Example 6 ‘1984-1X’
October, November, or December 1984
*/
func IsUnspecifiedDigit(edtf_str string) bool {
return re.UnspecifiedDigit.MatchString(edtf_str)
}
func ParseUnspecifiedDigit(edtf_str string) (*edtf.EDTFDate, error) {
/*
UNSPEC 156X-12-25 4 156X-12-25,156X,12,25
UNSPEC 15XX-12-25 4 15XX-12-25,15XX,12,25
UNSPEC 1XXX-XX 4 1XXX-XX,1XXX,XX,
UNSPEC 1XXX-12 4 1XXX-12,1XXX,12,
UNSPEC 1984-1X 4 1984-1X,1984,1X,
*/
if !re.UnspecifiedDigit.MatchString(edtf_str) {
return nil, edtf.Invalid(UNSPECIFIED_DIGIT, 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: UNSPECIFIED_DIGIT,
}
return d, nil
}