mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6239] [MERGED] feat(clients): renew on a calendar day instead of a rolling interval #6194
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6194
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6239
Author: @n0ctal
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-calendar-auto-renew📝 Commits (5)
bfa7168feat(clients): renew on a calendar day instead of a rolling interval0fa46b8fix(clients): persist the calendar renewal day on the client record9de6efcfix(clients): let the billing day be changed after creation5b6f244chore: drop the accidentally committed dist build stub45b1431Merge branch 'main' into pr/6239📊 Changes
34 files changed (+730 additions, -10 deletions)
View changed files
📝
frontend/public/openapi.json(+17 -0)📝
frontend/src/generated/examples.ts(+4 -0)📝
frontend/src/generated/schemas.ts(+15 -0)📝
frontend/src/generated/types.ts(+3 -0)📝
frontend/src/generated/zod.ts(+3 -0)📝
frontend/src/lib/remark/remarkVariables.ts(+1 -0)📝
frontend/src/pages/clients/ClientBulkAddModal.tsx(+11 -0)📝
frontend/src/pages/clients/ClientFormModal.tsx(+14 -0)📝
frontend/src/schemas/client.ts(+3 -0)📝
internal/database/model/model.go(+10 -0)📝
internal/sub/remark_vars.go(+5 -0)➖
internal/web/dist/.gitkeep(+0 -0)➕
internal/web/service/calendar_renew.go(+42 -0)➕
internal/web/service/calendar_renew_test.go(+116 -0)📝
internal/web/service/client_crud.go(+16 -0)📝
internal/web/service/client_link.go(+1 -0)📝
internal/web/service/client_paging.go(+4 -2)➕
internal/web/service/inbound_autorenew_calendar_test.go(+391 -0)📝
internal/web/service/inbound_node.go(+6 -5)📝
internal/web/service/inbound_traffic.go(+26 -3)...and 14 more files
📄 Description
Closes #6106.
Summary
Auto-renew advances the expiry by a fixed number of milliseconds. A client set to 30 days drifts against the calendar: renewing on 31 January lands on 2 March, and after a year the billing day has wandered a fortnight from wherever the operator's own plan resets.
This adds a per-client renewal day. When set, the expiry steps whole calendar months at midnight in the panel's configured time zone.
The two cases worth naming
Short months. A client billed on the 31st renews on 28 February and returns to 31 March. It does not decay to the 28th permanently, which is what "advance by one month" does if you implement it as "add 30 days" or let
time.Dateroll 31 February forward into March.Daylight saving. Because the step is a calendar operation in the panel's zone rather than an addition of hours, a renewal that crosses a DST boundary still lands on local midnight instead of drifting an hour twice a year.
Behaviour
resetDayper client, 0–31; 0 keeps today's interval mode, so existing clients are untouched.One defensive change
The interval branch now refuses a zero step. It is unreachable while the selection filter holds, and I kept it anyway: that loop is
for expiry < now { expiry += reset*24h }, it runs on the single traffic writer, and a zero interval reaching it would hang every panel mutation queued behind it. I found this while mutation-testing — removing the calendar branch turned the suite from failing into hanging, which is a considerably worse way to learn about it.Validation
Date arithmetic is covered directly: clamping in February (leap and common), returning to the 31st afterwards, 30-day months, December rolling into January, same-month vs next-month boundaries, the panel zone being honoured, and a DST crossing still landing on local midnight.
End to end through
autoRenewClients: a calendar client lands on its billing day with counters reset and re-enabled; a client billed on the 31st gets the clamped day; an interval client still moves by exactly the old fixed step.Mutation-checked: disabling the calendar branch turns the calendar test red; removing the short-month clamp turns the clamping tests red.
go build ./...,go vet,golangci-lint,make gen-checkclean; 36 Go packages green; frontend typecheck, eslint and the unit suite green.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.