-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.go
47 lines (35 loc) · 1.04 KB
/
date.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
package level0
import (
"github.com/sfomuseum/go-edtf"
"github.com/sfomuseum/go-edtf/common"
"github.com/sfomuseum/go-edtf/re"
)
/*
Date
complete representation: [year][“-”][month][“-”][day]
Example 1 ‘1985-04-12’ refers to the calendar date 1985 April 12th with day precision.
reduced precision for year and month: [year][“-”][month]
Example 2 ‘1985-04’ refers to the calendar month 1985 April with month precision.
reduced precision for year: [year]
Example 3 ‘1985’ refers to the calendar year 1985 with year precision.
*/
func IsDate(edtf_str string) bool {
return re.Date.MatchString(edtf_str)
}
func ParseDate(edtf_str string) (*edtf.EDTFDate, error) {
if !re.Date.MatchString(edtf_str) {
return nil, edtf.Invalid(DATE, 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: DATE,
}
return d, nil
}