summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2015-12-30 13:32:06 +0000
committerTed Trask <ttrask01@yahoo.com>2015-12-30 13:32:06 +0000
commitf2164d68cbe551f692b142392cde88c97c01c9a1 (patch)
tree07a57682e24b22badddbae67a84e77377930fc19
parent3cc4791d76c2612c5c86994b0bbdb67953c49cb8 (diff)
downloadacf-lib-f2164d68cbe551f692b142392cde88c97c01c9a1.tar.bz2
acf-lib-f2164d68cbe551f692b142392cde88c97c01c9a1.tar.xz
Add format.formatfilesize and formattime to create consistent user-friendly displays of file size and time
-rw-r--r--format.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/format.lua b/format.lua
index ec3e48d..b4250f8 100644
--- a/format.lua
+++ b/format.lua
@@ -23,6 +23,27 @@ function mymodule.escapespecialcharacters ( str )
return (string.gsub(str or "", "[~`#%$&%*%(%)\\|%[%]{};\'\"<>/\n\r]", "\\%1"))
end
+function mymodule.formatfilesize ( size )
+ size = tonumber(size) or 0
+ if ( size > 1073741824 ) then
+ return ((size/1073741824) - (size/1073741824%0.1)) .. "G"
+ elseif ( size > 1048576 ) then
+ return ((size/1048576) - (size/1048576%0.1)) .. "M"
+ elseif ( size > 1024 ) then
+ return ((size/1024) - (size/1024%0.1)) .. "k"
+ else
+ return tostring(size)
+ end
+end
+
+function mymodule.formattime ( time )
+ if tonumber(time) then
+ return os.date("%c", time)
+ else
+ return "---"
+ end
+end
+
-- search and remove all blank and commented lines from a string or table of lines
-- returns a table to iterate over without the blank or commented lines