MCPcopy
hub / github.com/wavetermdev/waveterm / FormatRelativeTime

Function FormatRelativeTime

pkg/util/utilfn/utilfn.go:1128–1168  ·  view source on GitHub ↗
(modTime time.Time)

Source from the content-addressed store, hash-verified

1126}
1127
1128func FormatRelativeTime(modTime time.Time) string {
1129 now := time.Now()
1130 diff := now.Sub(modTime)
1131
1132 if diff < time.Minute {
1133 return "just now"
1134 }
1135 if diff < time.Hour {
1136 minutes := int(diff.Minutes())
1137 if minutes == 1 {
1138 return "1 minute ago"
1139 }
1140 return fmt.Sprintf("%d minutes ago", minutes)
1141 }
1142 if diff < 24*time.Hour {
1143 hours := int(diff.Hours())
1144 if hours == 1 {
1145 return "1 hour ago"
1146 }
1147 return fmt.Sprintf("%d hours ago", hours)
1148 }
1149 if diff < 30*24*time.Hour {
1150 days := int(diff.Hours() / 24)
1151 if days == 1 {
1152 return "1 day ago"
1153 }
1154 return fmt.Sprintf("%d days ago", days)
1155 }
1156 if diff < 365*24*time.Hour {
1157 months := int(diff.Hours() / 24 / 30)
1158 if months == 1 {
1159 return "1 month ago"
1160 }
1161 return fmt.Sprintf("%d months ago", months)
1162 }
1163 years := int(diff.Hours() / 24 / 365)
1164 if years == 1 {
1165 return "1 year ago"
1166 }
1167 return fmt.Sprintf("%d years ago", years)
1168}

Callers 3

readTextFileCallbackFunction · 0.92
ReadDirFunction · 0.92
ReadDirRecursiveFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected