Skip to content

Commit

Permalink
Twitter widget now displays tweet times in relative, humanized terms
Browse files Browse the repository at this point in the history
  • Loading branch information
senorprogrammer committed Aug 25, 2018
1 parent 186c473 commit fb61cd5
Show file tree
Hide file tree
Showing 17 changed files with 1,202 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion twitter/tweet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ func (tweet *Tweet) Username() string {
return tweet.User.ScreenName
}

func (tweet *Tweet) PrettyCreatedAt() string {
func (tweet *Tweet) Created() time.Time {
newTime, _ := time.Parse(time.RubyDate, tweet.CreatedAt)
return newTime
}

func (tweet *Tweet) PrettyCreatedAt() string {
newTime := tweet.Created()
return fmt.Sprint(newTime.Format("Jan 2, 2006"))
}
9 changes: 7 additions & 2 deletions twitter/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"regexp"

"github.com/dustin/go-humanize"
"github.com/senorprogrammer/wtf/wtf"
)

Expand Down Expand Up @@ -93,9 +94,13 @@ func (widget *Widget) format(tweet Tweet) string {

var attribution string
if name == "" {
attribution = tweet.PrettyCreatedAt()
attribution = humanize.Time(tweet.Created())
} else {
attribution = fmt.Sprintf("%s, %s", name, tweet.PrettyCreatedAt())
attribution = fmt.Sprintf(
"%s, %s",
name,
humanize.Time(tweet.Created()),
)
}

return fmt.Sprintf("%s\n[grey]%s[white]\n\n", body, attribution)
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/dustin/go-humanize/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/dustin/go-humanize/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions vendor/github.com/dustin/go-humanize/README.markdown

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions vendor/github.com/dustin/go-humanize/big.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fb61cd5

Please sign in to comment.