this repo has no description

feat: move safeTimestamp to feeds.SafeTimestamp

+40 -31
+3
pkg/feeds/doc.go
··· 1 + package feeds 2 + 3 + // Common code usable by all feedgens
+35
pkg/feeds/timestamps.go
··· 1 + package feeds 2 + 3 + import ( 4 + "time" 5 + ) 6 + 7 + func SafeTimestamp(input string) int64 { 8 + utcNow := time.Now().UTC() 9 + if input == "" { 10 + return utcNow.Unix() 11 + } 12 + var t time.Time 13 + var err error 14 + layouts := []string{ 15 + time.RFC3339, 16 + } 17 + for _, layout := range layouts { 18 + if t, err = time.Parse(layout, input); err == nil { 19 + break 20 + } 21 + } 22 + if err != nil { 23 + return utcNow.Unix() 24 + } 25 + if t.Unix() <= 0 { 26 + return utcNow.Unix() 27 + } else if t.Add(-2*time.Minute).Compare(utcNow) == -1 { 28 + // accept as long as parsed time is no more than 2 minutes in the future 29 + return t.Unix() 30 + } else if t.Compare(utcNow) == 1 { 31 + return utcNow.Unix() 32 + } else { 33 + return utcNow.Unix() 34 + } 35 + }
+2 -31
pkg/mostliked/handler.go
··· 13 13 appbsky "github.com/bluesky-social/indigo/api/bsky" 14 14 jetstream "github.com/bluesky-social/jetstream/pkg/models" 15 15 db "github.com/edavis/bsky-feeds/db/mostliked" 16 + "github.com/edavis/bsky-feeds/pkg/feeds" 16 17 "github.com/karlseguin/ccache/v3" 17 18 _ "github.com/mattn/go-sqlite3" 18 19 "github.com/pemistahl/lingua-go" ··· 27 28 Languages []lingua.Language 28 29 Created int64 29 30 Likes int64 30 - } 31 - 32 - func safeTimestamp(input string) int64 { 33 - utcNow := time.Now().UTC() 34 - if input == "" { 35 - return utcNow.Unix() 36 - } 37 - var t time.Time 38 - var err error 39 - layouts := []string{ 40 - time.RFC3339, 41 - } 42 - for _, layout := range layouts { 43 - if t, err = time.Parse(layout, input); err == nil { 44 - break 45 - } 46 - } 47 - if err != nil { 48 - return utcNow.Unix() 49 - } 50 - if t.Unix() <= 0 { 51 - return utcNow.Unix() 52 - } else if t.Add(-2*time.Minute).Compare(utcNow) == -1 { 53 - // accept as long as parsed time is no more than 2 minutes in the future 54 - return t.Unix() 55 - } else if t.Compare(utcNow) == 1 { 56 - return utcNow.Unix() 57 - } else { 58 - return utcNow.Unix() 59 - } 60 31 } 61 32 62 33 func trimPostsTable(ctx context.Context, queries *db.Queries) { ··· 144 115 continue 145 116 } 146 117 draftPost := DraftPost{ 147 - Created: safeTimestamp(post.CreatedAt), 118 + Created: feeds.SafeTimestamp(post.CreatedAt), 148 119 Likes: 0, 149 120 } 150 121 if text := findDetectableText(post); text != "" {