feat: 添加时间间隔信息
This commit is contained in:
@@ -138,22 +138,43 @@ type RecordDataLite struct {
|
||||
}
|
||||
|
||||
func (r RecordDataLite) ToString() string {
|
||||
formatedStrRanked := "%s 使用 %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。"
|
||||
formatedStrUnranked := "%s 使用 %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。"
|
||||
formatedStrWithoutDevice := "%s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。"
|
||||
formatedStrWithoutDeviceAndRank := "%s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,准度为 %s。"
|
||||
formatedStrRanked := "%s,%s 使用 %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。"
|
||||
formatedStrUnranked := "%s, %s 使用 %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。"
|
||||
formatedStrWithoutDevice := "%s, %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。"
|
||||
formatedStrWithoutDeviceAndRank := "%s, %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。"
|
||||
hardStr := strings.Split(r.DifficultyRaw, "_")[1]
|
||||
layout := "2006-01-02 15:04:05.999999999-07:00"
|
||||
parsedTime, _ := time.Parse(layout, r.GeneratedTime)
|
||||
duration := time.Since(parsedTime)
|
||||
timeStr := timeConvert(duration)
|
||||
if r.Stars == 0 && r.DeviceHmd != "" {
|
||||
return fmt.Sprintf(formatedStrUnranked, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
return fmt.Sprintf(formatedStrUnranked, timeStr, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
} else if r.Stars != 0 && r.DeviceHmd != "" {
|
||||
return fmt.Sprintf(formatedStrRanked, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
return fmt.Sprintf(formatedStrRanked, timeStr, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
} else if r.Stars != 0 && r.DeviceHmd == "" {
|
||||
return fmt.Sprintf(formatedStrWithoutDevice, r.Name, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
return fmt.Sprintf(formatedStrWithoutDevice, timeStr, r.Name, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
} else {
|
||||
return fmt.Sprintf(formatedStrWithoutDeviceAndRank, r.Name, r.SongName, hardStr, r.Stars, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
return fmt.Sprintf(formatedStrWithoutDeviceAndRank, timeStr, r.Name, r.SongName, hardStr, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
}
|
||||
}
|
||||
|
||||
func timeConvert(duration time.Duration) string {
|
||||
var result string
|
||||
if duration.Hours() >= 24 {
|
||||
days := int(duration.Hours() / 24)
|
||||
result = fmt.Sprintf("%d天前", days)
|
||||
} else if duration.Hours() >= 1 {
|
||||
hours := int(duration.Hours())
|
||||
result = fmt.Sprintf("%d小时前", hours)
|
||||
} else if duration.Minutes() >= 1 {
|
||||
minutes := int(duration.Minutes())
|
||||
result = fmt.Sprintf("%d分钟前", minutes)
|
||||
} else {
|
||||
result = "刚刚"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
//用户信息
|
||||
|
||||
// ScoreStats 存储分数统计信息
|
||||
|
||||
Reference in New Issue
Block a user