mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-13 08:35:00 +03:00
fix(sub): convert far expiry dates to Jalali in constant time
gregorianToJalali walked the calendar one month at a time from a 2024
reference, so an expiry near the int64 limit (a node reports expiries
unchecked) cost seconds of CPU on every subscription fetch that renders
{{JALALI_EXPIRE_DATE}}. Jalali leap years repeat every 33 years, so
whole 33-year blocks are skipped before the walk.
This commit is contained in:
@@ -423,6 +423,13 @@ func gregorianToJalali(gy, gm, gd int) (jy, jm, jd int) {
|
||||
refJDN := 2460311
|
||||
days := int64(jdn - refJDN)
|
||||
jy, jm, jd = 1402, 10, 11
|
||||
// Leap years follow y % 33, so whole 33-year blocks are skipped: a node-reported expiry
|
||||
// can lie hundreds of millions of years away, and the walk below goes month by month.
|
||||
const jalaliCycleDays = 33*365 + 8
|
||||
if cycles := days / jalaliCycleDays; cycles != 0 {
|
||||
jy += int(cycles) * 33
|
||||
days -= cycles * jalaliCycleDays
|
||||
}
|
||||
|
||||
// Walk forward
|
||||
for days > 0 {
|
||||
|
||||
Reference in New Issue
Block a user