mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Twitter widget now displays tweet times in relative, humanized terms
This commit is contained in:
@@ -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"))
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user