calendar_expire.go 788 B

123456789101112131415161718192021
  1. package sub
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/mhsanaei/3x-ui/v3/internal/xray"
  6. )
  7. func (s *SubService) subscriptionUserinfo(traffic xray.ClientTraffic) string {
  8. expire := traffic.ExpiryTime / 1000
  9. if s.subCalendarExpireInclusive && traffic.ResetDay == 1 && traffic.ExpiryTime > 0 && s.calendarExpireLocation != nil {
  10. at := time.UnixMilli(traffic.ExpiryTime).In(s.calendarExpireLocation)
  11. midnight := at.Day() == 1 && at.Hour() == 0 && at.Minute() == 0 && at.Second() == 0 && at.Nanosecond() == 0
  12. if midnight && at.Add(-time.Second).Month() != at.Month() {
  13. // Opt-in last-valid-second presentation; never change the real cutoff (#6516).
  14. expire--
  15. }
  16. }
  17. return fmt.Sprintf("upload=%d; download=%d; total=%d; expire=%d", traffic.Up, traffic.Down, traffic.Total, expire)
  18. }