From cc839f935dec652e682e1289580e996d99feeedb Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 3 Dec 2020 19:23:59 -0800 Subject: [PATCH] better unit detection --- weed/storage/needle/volume_ttl.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/weed/storage/needle/volume_ttl.go b/weed/storage/needle/volume_ttl.go index 5368beaed..d0de3768e 100644 --- a/weed/storage/needle/volume_ttl.go +++ b/weed/storage/needle/volume_ttl.go @@ -145,6 +145,21 @@ func SecondsToTTL(seconds int32) string { if seconds == 0 { return "" } + if seconds%(3600*24*365) == 0 && seconds/(3600*24*365) < 256 { + return fmt.Sprintf("%dy", seconds/(3600*24*365)) + } + if seconds%(3600*24*30) == 0 && seconds/(3600*24*30) < 256 { + return fmt.Sprintf("%dM", seconds/(3600*24*30)) + } + if seconds%(3600*24*7) == 0 && seconds/(3600*24*7) < 256 { + return fmt.Sprintf("%dw", seconds/(3600*24*7)) + } + if seconds%(3600*24) == 0 && seconds/(3600*24) < 256 { + return fmt.Sprintf("%dd", seconds/(3600*24)) + } + if seconds%(3600) == 0 && seconds/(3600) < 256 { + return fmt.Sprintf("%dh", seconds/(3600)) + } if seconds/60 < 256 { return fmt.Sprintf("%dm", seconds/60) }