package srv_aicomment import ( "time" "videoweb/pub/models/playletmod" ) func PlayletPublishedAt(playlet *playletmod.Playlet) time.Time { if playlet == nil { return time.Time{} } if !playlet.OnlineAt.IsZero() { return playlet.OnlineAt } if !playlet.ReviewAt.IsZero() { return playlet.ReviewAt } return playlet.CreatedAt } func ScatteredCommentTime(publishedAt, endAt time.Time, objectID, commentID int64, index, total int) time.Time { if total <= 0 || index < 0 || index >= total || publishedAt.IsZero() || !publishedAt.Before(endAt) { return endAt } span := endAt.Sub(publishedAt) segment := span / time.Duration(total) segmentStart := segment * time.Duration(index) segmentEnd := segment * time.Duration(index+1) if index == total-1 { segmentEnd = span } width := segmentEnd - segmentStart if width <= 0 { return publishedAt.Add(segmentStart) } seed := scatterSeed(objectID, commentID, int64(index)) offset := time.Duration(seed % uint64(width)) return publishedAt.Add(segmentStart + offset) } func scatterSeed(values ...int64) uint64 { const ( offsetBasis = uint64(1469598103934665603) prime = uint64(1099511628211) ) hash := offsetBasis for _, value := range values { hash ^= uint64(value) hash *= prime } return hash }