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},
{"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)

View File

@ -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
}

View File

@ -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() {