pointer to timeresult

This commit is contained in:
Celogeek 2021-12-31 17:46:20 +01:00
parent 9190f23188
commit 1e948b887e
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
3 changed files with 14 additions and 11 deletions

View File

@ -58,7 +58,7 @@ func (c *ImageDetailsCommand) Execute(args []string) error {
{"Filename", resp.Filename}, {"Filename", resp.Filename},
{"Filesize", resp.Filesize}, {"Filesize", resp.Filesize},
{"Categories", strings.Join(resp.Categories.Names(), "\n")}, {"Categories", strings.Join(resp.Categories.Names(), "\n")},
{"Tags", strings.Join(resp.Tags.NamesWithAgeAt(resp.DateCreation), "\n")}, {"Tags", strings.Join(resp.Tags.NamesWithAgeAt(&resp.DateCreation), "\n")},
}) })
t.SetOutputMirror(os.Stdout) t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleLight) t.SetStyle(table.StyleLight)

View File

@ -16,15 +16,18 @@ type Tag struct {
ImageUrl string `json:"page_url"` ImageUrl string `json:"page_url"`
} }
func (c Tags) NamesWithAgeAt(createdAt TimeResult) []string { func (t Tags) NamesWithAgeAt(createdAt *TimeResult) []string {
names := make([]string, len(c)) names := make([]string, len(t))
for i, category := range c { for i, tag := range t {
bd := category.Birthdate.AgeAt(createdAt) names[i] = tag.NameWithAgeAt(createdAt)
if bd != "" {
names[i] = fmt.Sprintf("%s (%s)", category.Name, bd)
} else {
names[i] = category.Name
}
} }
return names return names
} }
func (t *Tag) NameWithAgeAt(createdAt *TimeResult) string {
bd := t.Birthdate.AgeAt(createdAt)
if bd != "" {
return fmt.Sprintf("%s (%s)", t.Name, bd)
}
return t.Name
}

View File

@ -44,7 +44,7 @@ func (c TimeResult) toTime() time.Time {
return time.Time(c) return time.Time(c)
} }
func (c TimeResult) AgeAt(createdAt TimeResult) string { func (c TimeResult) AgeAt(createdAt *TimeResult) string {
var year, month, day, hour, min, sec int var year, month, day, hour, min, sec int
a := c.toTime() a := c.toTime()
if a.IsZero() { if a.IsZero() {