-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterval.go
55 lines (39 loc) · 1.2 KB
/
interval.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
package level2
import (
// "fmt"
"github.com/sfomuseum/go-edtf"
"github.com/sfomuseum/go-edtf/common"
"github.com/sfomuseum/go-edtf/re"
//"strings"
)
/*
For Level 2 portions of a date within an interval may be designated as approximate, uncertain, or unspecified.
Example 1 ‘2004-06-~01/2004-06-~20’
An interval in June 2004 beginning approximately the first and ending approximately the 20th
Example 2 ‘2004-06-XX/2004-07-03’
An interval beginning on an unspecified day in June 2004 and ending July 3.
*/
func IsInterval(edtf_str string) bool {
return re.Interval.MatchString(edtf_str)
}
func ParseInterval(edtf_str string) (*edtf.EDTFDate, error) {
/*
INTERVAL 2004-06-~01/2004-06-~20 13 2004-06-~01/2004-06-~20,,2004,,06,~,01,,2004,,06,~,20
INTERVAL 2004-06-XX/2004-07-03 13 2004-06-XX/2004-07-03,,2004,,06,,XX,,2004,,07,,03
*/
if !re.Interval.MatchString(edtf_str) {
return nil, edtf.Invalid(INTERVAL, 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: INTERVAL,
}
return d, nil
}