From c7bc2092a6c728611d90525b08192f8a21fb625d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B0=D1=82=D0=BE=D0=BB=D0=B8=D0=B9=20=D0=A2?= =?UTF-8?q?=D1=83=D1=85=D1=82=D0=B0=D1=80=D0=BE=D0=B2?= Date: Wed, 10 Jan 2024 18:07:47 +0500 Subject: [PATCH] julia dates --- test.jl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test.jl b/test.jl index bad2607..226de68 100644 --- a/test.jl +++ b/test.jl @@ -1,9 +1,34 @@ # То же самое, но на julia using Logging +using Printf +using Dates + debuglogger = ConsoleLogger(stderr, Logging.Debug) global_logger(debuglogger) +# правильный перевод! +function humanbytes(B) + """Return the given bytes as a human friendly KB, MB, GB, or TB string.""" + B = float(B) + KB = float(1024) + MB = float(KB ^ 2) # 1,048,576 + GB = float(KB ^ 3) # 1,073,741,824 + TB = float(KB ^ 4) # 1,099,511,627,776 + + if B < KB + return @sprintf("%.2f Bytes", B) + elseif KB <= B && B < MB + return @sprintf("%.2f KB", (B / KB)) + elseif MB <= B && B < GB + return @sprintf("%.2f MB", (B / MB)) + elseif GB <= B && B < TB + return @sprintf("%.2f GB", (B / GB)) + elseif TB <= B + return @sprintf("%.2f TB", (B / KB)) + end +end + function new_name(name) matches = Dict( "Сек" => r"(.+) Сек.*", @@ -40,8 +65,10 @@ function file_info(filename) m = Dict( "filename" => filename, "size" => info.size, + "hsize" => humanbytes(info.size), "mtime" => info.mtime, "ctime" => info.ctime, + "htime" => Dates.format(Dates.unix2datetime(info.ctime), "dd.mm.yyyy"), "ext" => ext, ) return m