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 {
|
||||
unknownDate := "unknown"
|
||||
idx := len(dictionary.Entries) - 1
|
||||
if len(dictionary.Entries) == 0 {
|
||||
return "unknown"
|
||||
}
|
||||
dateEntry := dictionary.Entries[len(dictionary.Entries)-1]
|
||||
if len(dateEntry.Sense) == 0 || len(dateEntry.Sense[0].Glossary) == 0 {
|
||||
return "unknown"
|
||||
return unknownDate
|
||||
} else if len(dictionary.Entries[idx].Sense) == 0 {
|
||||
return unknownDate
|
||||
} else if len(dictionary.Entries[idx].Sense[0].Glossary) == 0 {
|
||||
return unknownDate
|
||||
}
|
||||
dateGloss := dictionary.Entries[idx].Sense[0].Glossary[0].Content
|
||||
r := regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)
|
||||
jmdictDate := r.FindString(dateEntry.Sense[0].Glossary[0].Content)
|
||||
if jmdictDate != "" {
|
||||
return jmdictDate
|
||||
date := r.FindString(dateGloss)
|
||||
if date != "" {
|
||||
return date
|
||||
} else {
|
||||
return "unknown"
|
||||
return unknownDate
|
||||
}
|
||||
}
|
||||
|
||||
|
21
jmnedict.go
21
jmnedict.go
@ -8,19 +8,22 @@ import (
|
||||
)
|
||||
|
||||
func jmnedictPublicationDate(dictionary jmdict.Jmnedict) string {
|
||||
unknownDate := "unknown"
|
||||
idx := len(dictionary.Entries) - 1
|
||||
if len(dictionary.Entries) == 0 {
|
||||
return "unknown"
|
||||
}
|
||||
dateEntry := dictionary.Entries[len(dictionary.Entries)-1]
|
||||
if len(dateEntry.Translations) == 0 || len(dateEntry.Translations[0].Translations) == 0 {
|
||||
return "unknown"
|
||||
return unknownDate
|
||||
} else if len(dictionary.Entries[idx].Translations) == 0 {
|
||||
return unknownDate
|
||||
} else if len(dictionary.Entries[idx].Translations[0].Translations) == 0 {
|
||||
return unknownDate
|
||||
}
|
||||
dateGloss := dictionary.Entries[idx].Translations[0].Translations[0]
|
||||
r := regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)
|
||||
jmnedictDate := r.FindString(dateEntry.Translations[0].Translations[0])
|
||||
if jmnedictDate != "" {
|
||||
return jmnedictDate
|
||||
date := r.FindString(dateGloss)
|
||||
if date != "" {
|
||||
return date
|
||||
} else {
|
||||
return "unknown"
|
||||
return unknownDate
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user