aboutsummaryrefslogtreecommitdiffstats
path: root/skate
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-07-25 12:46:00 -0700
committerBryan Newbold <bnewbold@archive.org>2021-07-25 12:46:00 -0700
commite038bfb6be24994ae9972d08f85c1cb1506a06b4 (patch)
tree35af6e986defa2a6049538b43f753ec9b3ba8a89 /skate
parentb2e4e4242c9d8d4fbdc026a80dfefa86697a5649 (diff)
downloadrefcat-e038bfb6be24994ae9972d08f85c1cb1506a06b4.tar.gz
refcat-e038bfb6be24994ae9972d08f85c1cb1506a06b4.zip
skate: use date-parts for year, not 'raw'
Diffstat (limited to 'skate')
-rw-r--r--skate/reduce.go13
-rw-r--r--skate/schema_test.go4
2 files changed, 9 insertions, 8 deletions
diff --git a/skate/reduce.go b/skate/reduce.go
index 356ed25..4cd604a 100644
--- a/skate/reduce.go
+++ b/skate/reduce.go
@@ -574,7 +574,7 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [
var (
authors []CSLAuthor
isbn string
- year string
+ issued *CSLDate
)
for _, name := range r.Biblio.ContribRawNames {
authors = append(authors, CSLAuthor{Name: name})
@@ -582,8 +582,11 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [
if len(r.Biblio.Extra.ISBN) > 0 {
isbn = r.Biblio.Extra.ISBN[0]
}
- if r.Biblio.Year > 1500 && r.Biblio.Year < 2022 {
- year = fmt.Sprintf("%d", r.Biblio.Year)
+ // TODO: need to update this "max year" number frequently?
+ if r.Biblio.Year > 1500 && r.Biblio.Year <= 2025 {
+ issued = &CSLDate{Parts: [][]int{{int(r.Biblio.Year)}}}
+ } else {
+ issued = &CSLDate{}
}
bref.TargetCSL = &CSL{
Author: authors,
@@ -598,9 +601,7 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [
Title: r.Biblio.Title,
URL: r.Biblio.Url,
Volume: r.Biblio.Volume,
- Issued: &CSLDate{
- Raw: year,
- },
+ Issued: issued,
}
}
// Reuse fields for debugging, for now.
diff --git a/skate/schema_test.go b/skate/schema_test.go
index 7616001..4489bed 100644
--- a/skate/schema_test.go
+++ b/skate/schema_test.go
@@ -263,10 +263,10 @@ func TestSchemaMarshal(t *testing.T) {
var csl = CSL{
Title: "test-doc",
Issued: &CSLDate{
- Raw: "2012",
+ Parts: [][]int{{2012}},
},
}
- var csl_json = []byte(`{"issued":{"raw":"2012"},"title":"test-doc"}`)
+ var csl_json = []byte(`{"issued":{"date-parts":[[2012]]},"title":"test-doc"}`)
var csl_encoded, _ = json.Marshal(csl)
if bytes.Compare(csl_json, csl_encoded) != 0 {
t.Fatalf("got:\n%v\nwant:\n%v\n", string(csl_json[:]), string(csl_encoded[:]))