diff options
author | Ted Trask <ttrask01@yahoo.com> | 2015-12-30 13:32:06 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2015-12-30 13:32:06 +0000 |
commit | f2164d68cbe551f692b142392cde88c97c01c9a1 (patch) | |
tree | 07a57682e24b22badddbae67a84e77377930fc19 | |
parent | 3cc4791d76c2612c5c86994b0bbdb67953c49cb8 (diff) | |
download | acf-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.lua | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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 |