Repository navigation
fix(billing): treat weekends and configured holidays as off-peak - #412
Merged
Merged
Conversation
Peak pricing only looked at the hour, so every day of the week was billed at the DeepSeek peak price between 9:00-12:00 and 14:00-18:00 Beijing time. DeepSeek's own rule is narrower: peak is Monday to Friday, excluding Chinese statutory holidays; weekends and holidays are off-peak for the whole day, at half the peak price. Weekends were therefore charged double. - is_peak_hour() takes the configured holiday dates and returns false on a weekend or on a listed date (rant 2026-10-16T14:08:13). - new optional [billing] holidays table (empty = weekends only), documented in config/config.example.toml; a malformed date fails at startup. rant: 2026-10-16T14:08:13.986531+08:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
billing::is_peak_hour()looked at the hour only, so every day of the week was billed at the DeepSeek peak price between 9:00-12:00 and 14:00-18:00 Beijing time. DeepSeek's own rule is narrower: peak is Monday to Friday, excluding Chinese statutory holidays; everything else — including weekends and holidays, all day — is off-peak, and the off-peak price is half the peak price. Sodeepseek-flash/deepseek-v4-procalls on a Saturday or Sunday were charged double: the platform billed users more than the upstream rule justifies.The weekday part is code; the statutory-holiday calendar is data, and it now comes from a new
[billing] holidaystable. The work order left that choice to the implementer and recommended configuration, because a table in code would force a release every year.Rant:
2026-10-16T14:08:13.986531+08:00— 【计费】高峰时段判定不看星期几 —— 周末按 2 倍价扣点,而 DeepSeek 官方在周末是空闲价 / "the peak-hour test ignores the day of the week — weekends are charged double, while DeepSeek charges the off-peak rate on weekends" (translated from the Chinese original).Related Issue
No issue — the input is this project's own rant queue; the rant timestamp is named above.
Changes
src/billing.rs—is_peak_hour(utc, holidays): a weekend returns off-peak; a date listed inholidaysreturns off-peak; the 9-12 / 14-18 window itself is unchanged. Doc comment updated.src/config.rs— newBilling { holidays: Vec<NaiveDate> }, optional ([billing]absent ⇒ empty table ⇒ weekends only), plus tests pinning theYYYY-MM-DDformat, the empty default, and a malformed date being a startup error.src/gateway.rs— the single production call site passes&st.cfg.billing.holidays.config/config.example.toml— new[billing]section documenting the rule and the table, and the[[models]]note no longer says the peak window is Monday to Sunday.config/config.tomlis gitignored and is not part of this repository, so this PR ships the tracked example only. An instance with no[billing]section gets the weekend fix immediately and exempts no holidays untilholidaysis filled in from the official annual calendar. No holiday dates are invented here — the shipped table is empty on purpose.Deliberately out of scope: the marketplace i18n strings (
mk.peak.title,mk.detail.peakVal) name the peak window (9-12 / 14-18) and stay true;effective_prices()'s "peak_* = 0means keep the off-peak price" semantics and every other pricing path are untouched.Tests
cargo test— 564 passed / 0 failed (562 onmain; this PR adds 2 config tests and rewrites the peak-hour test).src/billing.rs:327; restoring the guard makes it pass.cargo fmt --checkclean;cargo clippy --all-targets -- -D warningsclean.git grep 周一至周日→ zero hits in tracked files.Checklist
fix/…)config/config.example.toml