fix: sync sadhna calendar with local timezone

This commit is contained in:
Krispire Admin
2026-06-09 00:39:03 +05:30
parent 1f02ae26f6
commit 6c61e97bba
3 changed files with 62 additions and 16 deletions
+12 -8
View File
@@ -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)