Skip to content

IsPeakTime() 漏了「周一至周五」:周末 14 小时不打五折,四项价都翻倍 #6

Closed

Description

@xyzs996

IsPeakTime 把北京时间的小时算对了,但没看星期:

// pkg/pricing/pricing.go
func IsPeakTime(t time.Time) bool {
	beijing := t.In(time.FixedZone("UTC+8", 8*3600))
	h := beijing.Hour()
	return (h >= 9 && h < 12) || (h >= 14 && h < 18)
}

注释里引的那一页,原话是带星期的:

高峰时段为北京时间周一至周五 9:00 - 12:00、14:00 - 18:00(其余为空闲时段)。

英文页同一句:"Peak hours are 01:00 - 04:00 and 06:00 - 10:00 UTC, Monday through Friday (all other hours are off-peak)."

高峰一周 35 小时,不是 49 小时。现在周六、周日那 14 个小时里,PriceFor 不走那个 *= 0.5,四项(CacheHit / CacheMiss / Prompt / Output)全部按高峰价返回,是实际账单的两倍。

时区已经转好了,补一行就行:

// IsPeakTime 判断指定时间是否处于 DeepSeek 高峰时段。
// 高峰时段(北京时间): 周一至周五 9:00-12:00、14:00-18:00;其余(含整个周末)为空闲时段。
// 参考: https://api-docs.deepseek.com/zh-cn/quick_start/pricing
func IsPeakTime(t time.Time) bool {
	beijing := t.In(time.FixedZone("UTC+8", 8*3600))
	switch beijing.Weekday() {
	case time.Saturday, time.Sunday:
		return false
	}
	h := beijing.Hour()
	return (h >= 9 && h < 12) || (h >= 14 && h < 18)
}

顺带一提,这里在北京时区上取 Weekday() 正是该有的写法 —— 星期属于厂商那个时钟。换成 t.UTC().Weekday() 今天也全绿,因为两个窗口都在 16:00 UTC 之前收尾,而 UTC 那一天和北京那一天恰好从 16:00 UTC 起才分岔,168 个小时里两种读法算出来一模一样;等哪天窗口挪过 16:00 UTC 才会露馅,而那时候照着已公布窗口写的测试一条都红不了。

带日期的一致性向量(含那两个能把两种读法分开的时刻),CC0:https://github.com/xyzs996/deepseek-peak-offpeak-vectors

Activity

  1. Menfre01 commented on Aug 23, 2026

    @Menfre01
    Owner

    感谢 @xyzs996 的详细反馈!已确认问题属实并完成修复:

    • IsPeakTime 现按官方规则「北京时间周一至周五 9:00-12:00、14:00-18:00」判定,周六/周日全天按空闲时段半价计费
    • 新增回归测试 TestRegression_WeekendIsOffPeak 断言周末高峰窗口判空闲且价格减半
    • 修复随 v0.7.7 发布,变更日志已关联本 issue

    再次感谢反馈和修复建议(含时区/星期语义的分析),非常专业!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions