diff options
| author | mhsanaei <ho3ein.sanaei@gmail.com> | 2024-07-01 20:11:40 +0300 |
|---|---|---|
| committer | mhsanaei <ho3ein.sanaei@gmail.com> | 2024-07-01 20:11:40 +0300 |
| commit | 39aae6fd1625bd6a645368aa36b1e736f9e3d7f7 (patch) | |
| tree | fd5452ccb7d783649e67048b07a9f6f92c887345 | |
| parent | f355ab5758489a8cb70fc7431b503fba87b74150 (diff) | |
sub - add hour for time left
1D,10H⏳
22M⏳
| -rw-r--r-- | sub/subService.go | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/sub/subService.go b/sub/subService.go index cc73c6a1..899b231e 100644 --- a/sub/subService.go +++ b/sub/subService.go @@ -1007,9 +1007,37 @@ func (s *SubService) genRemark(inbound *model.Inbound, email string, extra strin now := time.Now().Unix() switch exp := stats.ExpiryTime / 1000; { case exp > 0: - remark = append(remark, fmt.Sprintf("%d%s⏳", (exp-now)/86400, "Days")) + remainingSeconds := exp - now + days := remainingSeconds / 86400 + hours := (remainingSeconds % 86400) / 3600 + minutes := (remainingSeconds % 3600) / 60 + if days > 0 { + if hours > 0 { + remark = append(remark, fmt.Sprintf("%dD,%dH⏳", days, hours)) + } else { + remark = append(remark, fmt.Sprintf("%dD⏳", days)) + } + } else if hours > 0 { + remark = append(remark, fmt.Sprintf("%dH⏳", hours)) + } else { + remark = append(remark, fmt.Sprintf("%dM⏳", minutes)) + } case exp < 0: - remark = append(remark, fmt.Sprintf("%d%s⏳", exp/-86400, "Days")) + passedSeconds := now - exp + days := passedSeconds / 86400 + hours := (passedSeconds % 86400) / 3600 + minutes := (passedSeconds % 3600) / 60 + if days > 0 { + if hours > 0 { + remark = append(remark, fmt.Sprintf("%dD,%dH⏳", days, hours)) + } else { + remark = append(remark, fmt.Sprintf("%dD⏳", days)) + } + } else if hours > 0 { + remark = append(remark, fmt.Sprintf("%dH⏳", hours)) + } else { + remark = append(remark, fmt.Sprintf("%dM⏳", minutes)) + } } } } |
