fix: sync sadhna calendar with local timezone
This commit is contained in:
@@ -243,18 +243,22 @@ func (r *PostRepo) PostedDates(ctx context.Context, userID string, since time.Ti
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// PostCountsByDate returns, for each UTC calendar day on or after `since`,
|
||||
// how many posts the user created that day. Keys are "YYYY-MM-DD"; days
|
||||
// with no posts are absent (so a missing key reads as zero). The sādhana
|
||||
// vine uses this both for the "posted a quote today" discipline and to
|
||||
// annotate each day's fold with the number of quotes shared.
|
||||
func (r *PostRepo) PostCountsByDate(ctx context.Context, userID string, since time.Time) (map[string]int, error) {
|
||||
// PostCountsByDate returns, for each calendar day on or after `since`, how
|
||||
// many posts the user created that day — bucketed in the given IANA timezone
|
||||
// (`tz`) so the day boundary matches the user's local midnight. Keys are
|
||||
// "YYYY-MM-DD"; days with no posts are absent (so a missing key reads as
|
||||
// zero). The sādhana page uses this for the "posted a quote today" discipline
|
||||
// and to annotate each day's fold with the number of quotes shared.
|
||||
func (r *PostRepo) PostCountsByDate(ctx context.Context, userID string, since time.Time, tz string) (map[string]int, error) {
|
||||
if tz == "" {
|
||||
tz = "UTC"
|
||||
}
|
||||
rows, err := r.pg.Pool.Query(ctx, `
|
||||
SELECT (created_at AT TIME ZONE 'UTC')::date AS d, count(*) AS n
|
||||
SELECT (created_at AT TIME ZONE $3)::date AS d, count(*) AS n
|
||||
FROM posts
|
||||
WHERE user_id = $1 AND created_at >= $2
|
||||
GROUP BY d`,
|
||||
userID, since,
|
||||
userID, since, tz,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("post counts by date: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user