Files
sub2api/backend/internal/service/custom_group_usage_rollup.go
T
李建琦 6d655c9903
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
2026-08-21 18:30:13 +08:00

41 lines
1.3 KiB
Go

package service
import (
"context"
"time"
appTimezone "github.com/Wei-Shaw/sub2api/internal/pkg/timezone"
)
const groupUsageDateFormat = "2006-01-02"
// GroupUsageRollupRepository 是分组日汇总的可选持久化能力。
type GroupUsageRollupRepository interface {
SyncGroupUsageRollups(ctx context.Context, todayStart time.Time) error
}
// GroupUsageTimezoneName 返回服务端配置的时区名称。
func GroupUsageTimezoneName() string {
return appTimezone.Location().String()
}
// GroupUsageTodayStart 返回指定时刻在服务端配置时区内的自然日 UTC 起点。
func GroupUsageTodayStart(at time.Time) time.Time {
return appTimezone.StartOfDay(at).UTC()
}
// GroupUsageYesterdayStart 返回指定时刻前一个本地日历日的 UTC 起点。
func GroupUsageYesterdayStart(at time.Time) time.Time {
return appTimezone.StartOfDay(at).AddDate(0, 0, -1).UTC()
}
// GroupUsageDate 返回指定时刻在服务端配置时区内的日期。
func GroupUsageDate(at time.Time) string {
return at.In(appTimezone.Location()).Format(groupUsageDateFormat)
}
// ParseGroupUsageDate 解析服务端配置时区内的日期并返回其零点。
func ParseGroupUsageDate(value string) (time.Time, error) {
return appTimezone.ParseInLocation(groupUsageDateFormat, value)
}