Module format : ajout d’une fonction de formatage des dates

This commit is contained in:
Benjamin VAUDOUR 2021-12-22 12:29:51 +00:00
parent 958f4a22ce
commit 3e66e82f8e
1 changed files with 24 additions and 0 deletions

View File

@ -177,3 +177,27 @@ fn list {|&with-header=$true &csep=' ' &hsep='-' &recompute=$true props data|
echo (line &sep=$csep $props $d)
} $data
}
fn size {|size|
var u = 0
var m = [
&10=Kio
&20=Mio
&30=Gio
]
while (< $u 30) {
var p = (math:pow 2 (+ $u 10))
if (< $size $p) {
break
}
set u = (to-string (+ $u 10))
}
if (== $u 0) {
put $size
} else {
var p = (math:pow 2 (+ $u 10))
var e = (/ $size $p)
printf '%.1f%s' $e $m[$u]
}
}