From 1e948b887e3b99ed7a8abb17d258b16f90f14d52 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Fri, 31 Dec 2021 17:46:20 +0100 Subject: [PATCH] pointer to timeresult --- cmd/piwigo-cli/images_details.go | 2 +- internal/piwigo/piwigotools/tags.go | 21 ++++++++++++--------- internal/piwigo/piwigotools/time_result.go | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/piwigo-cli/images_details.go b/cmd/piwigo-cli/images_details.go index 7504dc7..14b927c 100644 --- a/cmd/piwigo-cli/images_details.go +++ b/cmd/piwigo-cli/images_details.go @@ -58,7 +58,7 @@ func (c *ImageDetailsCommand) Execute(args []string) error { {"Filename", resp.Filename}, {"Filesize", resp.Filesize}, {"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.SetStyle(table.StyleLight) diff --git a/internal/piwigo/piwigotools/tags.go b/internal/piwigo/piwigotools/tags.go index f3e1f32..f5e129d 100644 --- a/internal/piwigo/piwigotools/tags.go +++ b/internal/piwigo/piwigotools/tags.go @@ -16,15 +16,18 @@ type Tag struct { ImageUrl string `json:"page_url"` } -func (c Tags) NamesWithAgeAt(createdAt TimeResult) []string { - names := make([]string, len(c)) - for i, category := range c { - bd := category.Birthdate.AgeAt(createdAt) - if bd != "" { - names[i] = fmt.Sprintf("%s (%s)", category.Name, bd) - } else { - names[i] = category.Name - } +func (t Tags) NamesWithAgeAt(createdAt *TimeResult) []string { + names := make([]string, len(t)) + for i, tag := range t { + names[i] = tag.NameWithAgeAt(createdAt) } 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 +} diff --git a/internal/piwigo/piwigotools/time_result.go b/internal/piwigo/piwigotools/time_result.go index 6e71e83..fc9c1b7 100644 --- a/internal/piwigo/piwigotools/time_result.go +++ b/internal/piwigo/piwigotools/time_result.go @@ -44,7 +44,7 @@ func (c TimeResult) toTime() time.Time { 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 a := c.toTime() if a.IsZero() {