新增获取会员订单列表-最近下单

This commit is contained in:
2024-08-13 14:07:31 +08:00
parent 4b8671a765
commit 068830fff7
5 changed files with 130 additions and 0 deletions
+26
View File
@@ -1,6 +1,7 @@
package utils
import (
"fmt"
"hepa-calc-api/api/model"
"time"
)
@@ -22,3 +23,28 @@ func StrToLocalTime(s string) (*model.LocalTime, error) {
return &t, nil
}
// TimeToAgoString 根据给定的时间返回一个描述性的字符串
func TimeToAgoString(t time.Time) string {
now := time.Now()
diffTime := now.Sub(t)
switch {
case diffTime < time.Minute:
return "1分钟前"
case diffTime < time.Hour:
minutes := int(diffTime.Minutes())
return fmt.Sprintf("%d分钟前", minutes)
case diffTime < 24*time.Hour:
return "一小时前"
case diffTime < 48*time.Hour:
return "两天前"
case diffTime < 72*time.Hour:
return "三天前"
case diffTime < 10*time.Hour*24:
days := int(diffTime.Hours()) / 24
return fmt.Sprintf("%d天前", days)
default:
return "十天前"
}
}