Improve readability of publication date functions
This commit is contained in:
parent
a9d85dc720
commit
ecf22da5a3
21
jmdict.go
21
jmdict.go
@ -63,19 +63,22 @@ func doDisplaySenseNumberTag(headword headword, entry jmdict.JmdictEntry, meta j
|
|||||||
}
|
}
|
||||||
|
|
||||||
func jmdictPublicationDate(dictionary jmdict.Jmdict) string {
|
func jmdictPublicationDate(dictionary jmdict.Jmdict) string {
|
||||||
|
unknownDate := "unknown"
|
||||||
|
idx := len(dictionary.Entries) - 1
|
||||||
if len(dictionary.Entries) == 0 {
|
if len(dictionary.Entries) == 0 {
|
||||||
return "unknown"
|
return unknownDate
|
||||||
}
|
} else if len(dictionary.Entries[idx].Sense) == 0 {
|
||||||
dateEntry := dictionary.Entries[len(dictionary.Entries)-1]
|
return unknownDate
|
||||||
if len(dateEntry.Sense) == 0 || len(dateEntry.Sense[0].Glossary) == 0 {
|
} else if len(dictionary.Entries[idx].Sense[0].Glossary) == 0 {
|
||||||
return "unknown"
|
return unknownDate
|
||||||
}
|
}
|
||||||
|
dateGloss := dictionary.Entries[idx].Sense[0].Glossary[0].Content
|
||||||
r := regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)
|
r := regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)
|
||||||
jmdictDate := r.FindString(dateEntry.Sense[0].Glossary[0].Content)
|
date := r.FindString(dateGloss)
|
||||||
if jmdictDate != "" {
|
if date != "" {
|
||||||
return jmdictDate
|
return date
|
||||||
} else {
|
} else {
|
||||||
return "unknown"
|
return unknownDate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
jmnedict.go
21
jmnedict.go
@ -8,19 +8,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func jmnedictPublicationDate(dictionary jmdict.Jmnedict) string {
|
func jmnedictPublicationDate(dictionary jmdict.Jmnedict) string {
|
||||||
|
unknownDate := "unknown"
|
||||||
|
idx := len(dictionary.Entries) - 1
|
||||||
if len(dictionary.Entries) == 0 {
|
if len(dictionary.Entries) == 0 {
|
||||||
return "unknown"
|
return unknownDate
|
||||||
}
|
} else if len(dictionary.Entries[idx].Translations) == 0 {
|
||||||
dateEntry := dictionary.Entries[len(dictionary.Entries)-1]
|
return unknownDate
|
||||||
if len(dateEntry.Translations) == 0 || len(dateEntry.Translations[0].Translations) == 0 {
|
} else if len(dictionary.Entries[idx].Translations[0].Translations) == 0 {
|
||||||
return "unknown"
|
return unknownDate
|
||||||
}
|
}
|
||||||
|
dateGloss := dictionary.Entries[idx].Translations[0].Translations[0]
|
||||||
r := regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)
|
r := regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)
|
||||||
jmnedictDate := r.FindString(dateEntry.Translations[0].Translations[0])
|
date := r.FindString(dateGloss)
|
||||||
if jmnedictDate != "" {
|
if date != "" {
|
||||||
return jmnedictDate
|
return date
|
||||||
} else {
|
} else {
|
||||||
return "unknown"
|
return unknownDate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user