Skip to content

Commit

Permalink
Merge pull request #144 from aschnell/master
Browse files Browse the repository at this point in the history
- use correct binary prefix (see bnc#849276)
  • Loading branch information
jreidinger committed Nov 15, 2013
2 parents ad7ec30 + f980430 commit 91f6869
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 37 deletions.
28 changes: 14 additions & 14 deletions library/types/src/modules/String.rb
Expand Up @@ -121,35 +121,35 @@ def YesNo(value)
# Return a pretty description of a byte count
#
# Return a pretty description of a byte count with required precision
# and using B, kB, MB, GB or TB as unit as appropriate.
# and using B, KiB, MiB, GiB or TiB as unit as appropriate.
#
# Uses the current locale defined decimal separator
# (i.e. the result is language dependant).
#
# @param [Fixnum] bytes size (e.g. free diskspace, memory size) in Bytes
# @param [Fixnum] precision number of fraction digits in output, if negative (less than 0) the precision is set automatically depending on the suffix
# @param [Boolean] omit_zeroes if true then do not add zeroes
# (useful for memory size - 128 MB RAM looks better than 128.00 MB RAM)
# (useful for memory size - 128 MiB RAM looks better than 128.00 MiB RAM)
# @return formatted string
#
# @example FormatSizeWithPrecision(128, 2, true) -> "128 B"
# @example FormatSizeWithPrecision(4096, 2, true) -> "4 kB"
# @example FormatSizeWithPrecision(4096, 2, false) -> "4.00 kB"
# @example FormatSizeWithPrecision(1024*1024, 2, true) -> "1 MB"
# @example FormatSizeWithPrecision(4096, 2, true) -> "4 KiB"
# @example FormatSizeWithPrecision(4096, 2, false) -> "4.00 KiB"
# @example FormatSizeWithPrecision(1024*1024, 2, true) -> "1 MiB"
def FormatSizeWithPrecision(bytes, precision, omit_zeroes)
return "" if bytes == nil

units = [
# Byte abbreviated
_("B"),
# KiloByte abbreviated
_("kB"),
_("KiB"),
# MegaByte abbreviated
_("MB"),
_("MiB"),
# GigaByte abbreviated
_("GB"),
_("GiB"),
# TeraByte abbreviated
_("TB")
_("TiB")
]

index = 0
Expand Down Expand Up @@ -205,26 +205,26 @@ def FormatSizeWithPrecision(bytes, precision, omit_zeroes)
# Return a pretty description of a byte count
#
# Return a pretty description of a byte count, with two fraction digits
# and using B, kB, MB, GB or TB as unit as appropriate.
# and using B, KiB, MiB, GiB or TiB as unit as appropriate.
#
# Uses the current locale defined decimal separator
# (i.e. the result is language dependant).
#
# @param [Fixnum] bytes size (e.g. free diskspace) in Bytes
# @return formatted string
#
# @example FormatSize(23456767890) -> "223.70 MB"
# @example FormatSize(23456767890) -> "223.70 MiB"
def FormatSize(bytes)
return "" if bytes == nil

# automatic precision, don't print trailing zeroes for sizes < 1MB
# automatic precision, don't print trailing zeroes for sizes < 1MiB
FormatSizeWithPrecision(bytes, -1, Ops.less_than(bytes, 1 << 20))
end

# Return a pretty description of a download rate
#
# Return a pretty description of a download rate, with two fraction digits
# and using B/s, kB/s, MB/s, GB/s or TB/s as unit as appropriate.
# and using B/s, KiB/s, MiB/s, GiB/s or TiB/s as unit as appropriate.
#
# @param [Fixnum] bytes_per_second download rate (in B/s)
# @return formatted string
Expand All @@ -234,7 +234,7 @@ def FormatSize(bytes)
# @example FormatRate(895321) -> ""
def FormatRate(bytes_per_second)
# covert a number to download rate string
# %1 is string - size in bytes, B, kB, MB, GB or TB
# %1 is string - size in bytes, B, KiB, MiB, GiB or TiB
Builtins.sformat(_("%1/s"), FormatSize(bytes_per_second))
end

Expand Down
46 changes: 23 additions & 23 deletions library/types/testsuite/tests/String.out
Expand Up @@ -14,34 +14,34 @@ Dump String::FormatSize
Return
Return 0 B
Return 1 B
Return 1 kB
Return 1.1 kB
Return 743 kB
Return 1.00 MB
Return 1.000 GB
Return 1.000 TB
Return 1024.091 TB
Return 1 kB
Return 1.00 MB
Return 1.000 GB
Return 1.000 TB
Return 1 KiB
Return 1.1 KiB
Return 743 KiB
Return 1.00 MiB
Return 1.000 GiB
Return 1.000 TiB
Return 1024.091 TiB
Return 1 KiB
Return 1.00 MiB
Return 1.000 GiB
Return 1.000 TiB
Dump String::FormatSizeWithPrecision
Return
Return 0 B
Return 1.00 B
Return 1.001 kB
Return 1 MB
Return 1 MB
Return 1 GB
Return 1.000 GB
Return 1.00 TB
Return 1024.1 TB
Return 4 kB
Return 4.00 kB
Return 4 kB
Return 8 GB
Return 1.001 KiB
Return 1 MiB
Return 1 MiB
Return 1 GiB
Return 1.000 GiB
Return 1.00 TiB
Return 1024.1 TiB
Return 4 KiB
Return 4.00 KiB
Return 4 KiB
Return 8 GiB
Return 15.00000 B
Return 21.846 GB
Return 21.846 GiB
Dump String::CutBlanks
Return
Return
Expand Down
5 changes: 5 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Wed Nov 13 17:08:09 CET 2013 - aschnell@suse.de

- use correct binary prefix (see bnc#849276)

-------------------------------------------------------------------
Mon Nov 11 10:48:14 UTC 2013 - jsrain@suse.cz

Expand Down

0 comments on commit 91f6869

Please sign in to comment.