Humanize numbers: data sizes, datetime deltas, digit separators
Julia
Latest commit cc763c0 Jul 24, 2016 @IainNZ committed on GitHub Update .travis.yml
Permalink
Failed to load latest commit information.
src 0.4 only update Aug 30, 2015
test 0.4 only update Aug 30, 2015
.travis.yml Update .travis.yml Jul 24, 2016
LICENSE.md Digitsep: Separate digit groups in integers Oct 5, 2014
README.md Update README.md Jul 24, 2016
REQUIRE 0.4 only update Aug 30, 2015

README.md

Humanize.jl

Build Status codecov

Humanize Humanize

Humanize numbers, including

  • data sizes (3e6 -> 3.0 MB or 2.9 MiB).
  • Date/datetime differences (Date(2014,2,3) - Date(2013,3,7) -> 1 year, 1 month)
  • Digit separator (12345678 -> 12,345,678)

This package is MIT licensed, and is based on jmoiron's humanize Python library.

Installation: Pkg.add("Humanize")

Documentation

All functions are also documented using Julia's in-built help system, e.g. ?datasize.

Data sizes

datasize(value::Number; style=:dec, format="%.1f")

Style can be :dec (base 10^3), :bin (base 2^10), :gnu (base 2^10, like ls -hs).

julia> datasize(3000000)
"3.0 MB"
julia> datasize(3000000, style=:bin, format="%.3f")
"2.861 MiB"
julia> datasize(3000000, style=:gnu, format="%.3f")
"2.861M"

Date/datetime differences

timedelta(secs::Integer)
timedelta{T<:Integer}(years::T,months::T,days::T,hours::T,mins::T,secs::T)
timedelta(dt_diff::Dates.Millisecond)
timedelta(d_diff::Dates.Day)

Turns a date/datetime difference into a abbreviated human-friendly form.

julia> timedelta(70)
"a minute"
julia> timedelta(0,0,0,23,50,50)
"23 hours"
julia> timedelta(DateTime(2014,2,3,12,11,10) - 
                    DateTime(2013,3,7,13,1,20))
"11 months"
julia> timedelta(Date(2014,3,7) - Date(2013,2,4))
"1 year, 1 month"

Digit separator

julia> digitsep(12345678)
"12,345,678"
julia> digitsep(12345678, sep = "'")
"12'345'678"
julia> digitsep(12345678, sep = "-", k = 4)
"1234-5678"